POJ 2796Feel Good
来源:互联网 发布:mac 强制关掉程序 编辑:程序博客网 时间:2024/05/21 07:59
#include<cstdio>#include<iostream>#include<algorithm>using namespace std;#define N 100010#define ll __int64struct S{ int startPos; ll h; S(int start=0,ll hh=0){ startPos=start; h=hh; }}stack[N];struct Node{ ll cj; int l,r; Node(ll cc=0,int ww=0,int hh=0){ cj=cc; l=ww; r=hh; }}res;S st;int n;ll sum[N];ll a[N];int main(){ while(~scanf("%d",&n)){ int top=0; scanf("%I64d",&a[0]); sum[0]=a[0]; for(int i=1;i<n;i++){ scanf("%I64d",&a[i]); sum[i]=sum[i-1]+a[i]; } st.startPos=0; st.h=a[0]; stack[top]=st; res.cj=a[0]*a[0]; res.l=0; res.r=0; for(int i=1;i<n;i++){ st.startPos=i; while(top>=0 && a[i]<stack[top].h){ //puts("1"); st=stack[top];//更新起点的位置 top--; ll ww=0; if(st.startPos==0) ww=sum[i-1]; else ww=sum[i-1]-sum[st.startPos-1]; ll ans=st.h*(ww); if(res.cj<ans) res.cj=ans,res.l=st.startPos,res.r=i-1; } st.h=a[i]; stack[++top]=st; } while(top>=0) { ll ww=0; if(st.startPos==0) ww=sum[n-1]; else ww=sum[n-1]-sum[stack[top].startPos-1]; ll temp = stack[top].h*ww; if(res.cj<temp) res.cj=temp,res.l=stack[top].startPos,res.r=n-1; //printf("posl=%d posr=%d\n",res.l,res.r); top--; } printf("%I64d\n",res.cj); printf("%d %d\n",res.l+1,res.r+1); }}
0 0
- poj 2796 Feel Good
- POJ 2796 Feel Good
- POJ 2796 Feel Good
- poj 2796 Feel Good
- poj 2796 feel good
- POJ-2796-Feel Good
- POJ 2796Feel Good
- poj 2796 Feel Good
- POJ 2796 Feel Good
- poj 2796 Feel Good
- Poj-2796 Feel Good
- POJ 2796 Feel Good
- poj 2796 Feel Good
- poj 2796Feel Good
- POJ 2796 Feel Good
- POJ 2796 Feel Good
- poj 2796 Feel Good
- POJ 2796 Feel Good
- 多线程总结笔记
- 使用tcgetattr函数与tcsetattr函数控制终端
- sql查询模板
- Android开发之四大组件——Service
- 汇编入门学习笔记 (十二)—— int指令、端口
- POJ 2796Feel Good
- Struts2 OGNL 自己的一些笔记
- 真正的成功是熬出来的
- Session && Cookie
- 不要做一个浮躁的程序员
- 依赖倒转原则
- eclipse+selenium环境搭建
- atexit函数
- 循环-01. 求整数段和(15)