标签:mit cep average cat was span break input idt
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 15375 | Accepted: 4252 | |
Case Time Limit: 1000MS | Special Judge |
Description
Input
Output
Sample Input
6 3 1 6 4 5 2
Sample Output
60 3 5
Source
1 #include <algorithm> 2 #include <cstring> 3 #include <cstdio> 4 5 using namespace std; 6 7 #define LL long long 8 const int N(100000+5); 9 int ans_l,ans_r,l[N],r[N]; 10 LL n,ans_val=-1,sum[N],val[N]; 11 12 inline void read(LL &x) 13 { 14 x=0; LL ch=getchar(); 15 for(;ch>‘9‘||ch<‘0‘;) ch=getchar(); 16 for(;ch>=‘0‘&&ch<=‘9‘;ch=getchar()) x=ch-‘0‘+x*10; 17 } 18 19 int main() 20 { 21 read(n); 22 for(int i=1;i<=n;i++) 23 { 24 read(val[i]),l[i]=r[i]=i; 25 sum[i]=sum[i-1]+val[i]; 26 } 27 for(int i=2;i<=n;i++) 28 for(;l[i]>1&&val[l[i]-1]>=val[i];) 29 l[i]=l[l[i]-1]; 30 for(int i=n-1;i>=1;i--) 31 for(;r[i]<n&&val[r[i]+1]>=val[i];) 32 r[i]=r[r[i]+1]; 33 for(int i=1;i<=n;i++) 34 { 35 LL tmp=val[i]*(sum[r[i]]-sum[l[i]-1]); 36 if(tmp>ans_val) 37 { 38 ans_l=l[i]; 39 ans_r=r[i]; 40 ans_val=tmp; 41 } 42 } 43 printf("%I64d\n%d %d",ans_val,ans_l,ans_r); 44 return 0; 45 }
标签:mit cep average cat was span break input idt
原文地址:http://www.cnblogs.com/Shy-key/p/7391057.html