Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
一定要注意最大值为0的情况啊#include<stdio.h> int n,t,al,ar; int lmax[100001],rmax[100001],q[100001]; long long a[100001],ans,sum[100001]; int main() { scanf("%d",&n); int i; for(i=1;i<=n;i++) { scanf("%I64d",&a[i]); sum[i]=sum[i-1]+a[i]; } a[0]=-1; a[n+1]=-1; t=0; q[0]=0; for(i=1;i<=n;i++) { while(t>0&&a[q[t]]>=a[i]) t--; lmax[i]=q[t]; q[++t]=i; } t=0; q[0]=n+1; for(i=n;i>=1;i--) { while(t>0&&a[q[t]]>=a[i]) t--; rmax[i]=q[t]; q[++t]=i; } ans=-1; for(i=1;i<=n;i++) { if(ans<a[i]*(sum[rmax[i]-1]-sum[lmax[i]])) { ans=a[i]*(sum[rmax[i]-1]-sum[lmax[i]]); al=lmax[i]+1; ar=rmax[i]-1; } } printf("%I64d\n%d %d",ans,al,ar); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator