标签:
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 12409 | Accepted: 3484 | |
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<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #define ll long long 5 using namespace std; 6 ll n; 7 ll a[100005]; 8 ll sum[100005]; 9 ll l[100005],r[100005]; 10 ll ans; 11 int gg; 12 int main() 13 { 14 gg=0; 15 while(scanf("%lld",&n)!=EOF) 16 { 17 if(gg) 18 cout<<endl; 19 gg++; 20 sum[0]=0; 21 ans=-1; 22 int flag=0; 23 for(int i=1;i<=n;i++) 24 { 25 scanf("%lld",&a[i]); 26 sum[i]=sum[i-1]+a[i]; 27 } 28 a[0]=-1;a[n+1]=-1; 29 l[1]=1; 30 for(int i=2;i<=n;i++)//关键******** 31 { 32 int temp=i-1; 33 while(a[temp]>=a[i])//维护一个递增的序列 34 temp=l[temp]-1; 35 l[i]=temp+1; 36 } 37 r[n]=n; 38 for (int i=n-1;i>=1;i--) 39 { 40 int temp=i+1; 41 while(a[temp]>=a[i]) 42 temp=r[temp]+1; 43 r[i]=temp-1; 44 } 45 for(int i=1;i<=n;i++) 46 { 47 ll ggg=(sum[r[i]]-sum[l[i]-1])*a[i]; 48 if(ggg>ans) 49 flag=i; 50 ans=max(ans,ggg); 51 } 52 printf("%lld\n",ans); 53 printf("%lld %lld\n",l[flag],r[flag]); 54 } 55 return 0; 56 }
标签:
原文地址:http://www.cnblogs.com/hsd-/p/5659673.html