单调栈还没有完全理解...写了个优雅的暴力AC了...
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const int maxn=100000+10; long long a[maxn],sum[maxn]; int L[maxn],R[maxn]; int n; int main() { while(~scanf("%d",&n)) { sum[0]=0; for(int i=1;i<=n;i++) { scanf("%lld",&a[i]); sum[i]=sum[i-1]+a[i]; } for(int i=1;i<=n;i++) L[i]=i; for(int i=2;i<=n;i++) { if(a[i]>a[i-1]) continue; int pre=L[i-1]; while(1) { L[i]=pre; if(pre==1||a[pre-1]<a[i]) break; pre=L[pre-1]; } } for(int i=n;i>=1;i--) R[i]=i; for(int i=n-1;i>=1;i--) { if(a[i]>a[i+1]) continue; int pre=R[i+1]; while(1) { R[i]=pre; if(pre==n||a[pre+1]<a[i]) break; pre=R[pre+1]; } } long long ans1=-1; int ans2,ans3; for(int i=1;i<=n;i++){ if(ans1<a[i]*(sum[R[i]]-sum[L[i]-1])) { ans1=a[i]*(sum[R[i]]-sum[L[i]-1]); ans2=L[i]; ans3=R[i]; } } printf("%lld ",ans1); printf("%d %d ",ans2,ans3); } return 0; }