poj 2796
来源:互联网 发布:淘宝上怎么设置折扣 编辑:程序博客网 时间:2024/06/05 09:43
poj 2796
原题
题意:
给定一个长度为
思路:
对于
当最小值
枚举每个点为区间最小值,取所有情况的最大值,复杂度
注意答案会爆int。
单调栈:
# include<stdio.h>const int NMax=100000;int n, ansL, ansR, in[NMax+1], range[NMax+1][2];long long sum[NMax+1], ans;struct Stack{ int id[NMax+1]; int top; void Init(){top=0;} void Pop(){top--;} void Push(int i){id[top++]=i;} bool Empty(){return top==0;} int Head(){return id[top-1];}}sta;int main(){ int i; scanf("%d", &n); ans=(1<<31); sum[0]=0; sta.Init(); for(int i=1; i<=n; i++){ scanf("%d", in+i); sum[i]=sum[i-1]+in[i]; } for(int i=1; i<=n; i++){ while(!sta.Empty() && in[sta.Head()]>=in[i]){ range[sta.Head()][1]=i-1; sta.Pop(); } range[i][0]=sta.Empty()?1:sta.Head()+1; sta.Push(i); } while(!sta.Empty()){ range[sta.Head()][1]=n; sta.Pop(); } for(int i=1; i<=n; i++){ long long tans; tans=(sum[range[i][1]]-sum[range[i][0]-1])*in[i]; if(tans>ans){ ans=tans; ansL=range[i][0]; ansR=range[i][1]; } } printf("%lld\n%d %d\n", ans, ansL, ansR); return 0;}
0 0
- POJ 2796
- poj 2796
- poj 2796
- POJ 2796
- poj 2796
- poj 2796
- poj 2796
- poj 2796 数字求和
- poj 2796 Feel Good
- poj 2796#单调栈
- POJ 2796 Feel Good
- POJ 2796 Feel Good
- poj 2796 Feel Good
- poj 2796 feel good
- POJ 2796 单调栈~
- POJ-2796-Feel Good
- POJ 2796Feel Good
- poj 2796 Feel Good
- 【985系列】985的买饮料难题
- Neerc2005 POJ2794 Double Patience
- MongoDB数据操作
- BOM
- 原型图工具功能比拼1
- poj 2796
- Modular Programming with JavaScript-Packt Publishing 2016(读书笔记)
- 二分图最大匹配模板
- java工程_web.xml配置session有效期
- 对象锁和类锁的区别
- 实例:ABAP权限对象设计与权限检查的实现(详细)
- linux4.4安装实时补丁性能差异
- iptables 详解
- hdu 5839 Special Tetrahedron (判断四面体)