标签:
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 13376 | Accepted: 3719 | |
Case Time Limit: 1000MS | Special Judge |
Description
Input
Output
Sample Input
6 3 1 6 4 5 2
Sample Output
60 3 5
Source
// // main.cpp // poj2796 // // Created by Candy on 10/5/16. // Copyright © 2016 Candy. All rights reserved. // #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; typedef long long ll; const int N=1e5+5; inline int read(){ char c=getchar();int x=0,f=1; while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1;c=getchar();} while(c>=‘0‘&&c<=‘9‘){x=x*10+c-‘0‘;c=getchar();} return x; } int n; ll a,ans=-1,ansb,anse; struct data{ ll h,l; int b; }st[N]; int top=0; int main(int argc, const char * argv[]) { n=read(); for(int i=1;i<=n;i++){ a=read(); ll right=0;int b=i; while(top&&st[top].h>=a){ ll tmp=(st[top].h*(st[top].l+right)); right+=st[top].l; b=st[top].b; if(tmp>ans){ ans=tmp; ansb=st[top].b; anse=i-1;//printf("t %lld %lld %lld\n",ans,ansb,anse); } top--; } top++; st[top].h=a; st[top].l=right+a; st[top].b=b; } ll right=0; while(top){ ll tmp=(st[top].h*(st[top].l+right)); right+=st[top].l; if(tmp>ans){ ans=tmp; ansb=st[top].b; anse=n; } top--; } printf("%lld\n%lld %lld",ans,ansb,anse); return 0; }
标签:
原文地址:http://www.cnblogs.com/candy99/p/5933202.html