标签:
Description
Input
Output
Sample Input
7 2 1 4 5 1 3 3 4 1000 1000 1000 1000 0
Sample Output
8 4000
Hint
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <stack> 6 using namespace std; 7 #define maxn 111111 8 typedef long long LL; 9 int a[maxn],L[maxn],R[maxn]; 10 stack<int>S; 11 int main() 12 { 13 int n; 14 while(scanf("%d",&n)&&n) 15 { 16 while(!S.empty()) S.pop(); 17 for(int i=1; i<=n; i++) scanf("%d",&a[i]); 18 for(int i=1; i<=n; i++) 19 { 20 while(!S.empty()&&a[S.top()]>=a[i]) S.pop(); 21 if(!S.empty()) L[i]=S.top(); 22 else L[i]=0; 23 S.push(i); 24 } 25 while(!S.empty()) S.pop(); 26 for(int i=n; i>=1; i--) 27 { 28 while(!S.empty()&&a[S.top()]>=a[i]) S.pop(); 29 if(!S.empty()) R[i]=S.top(); 30 else R[i]=n+1; 31 S.push(i); 32 } 33 LL ans=0; 34 for(int i=1; i<=n; i++) ans=max(ans,(LL)(R[i]-L[i]-1)*a[i]); 35 printf("%I64d\n",ans); 36 } 37 return 0; 38 }
标签:
原文地址:http://www.cnblogs.com/demodemo/p/4678377.html