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 |
DP的思想#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; typedef long long LL; const int MAXN = 100050; LL a[MAXN], sum[MAXN]; LL L[MAXN], R[MAXN]; int n; int main () { scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%lld", &a[i]); sum[i] = sum[i - 1] + a[i]; L[i] = R[i] = i; } a[0] = a[n + 1] = -1; for(int i = 1; i <= n; i++) { while(a[i] <= a[L[i] - 1]) L[i] = L[L[i] - 1]; } for(int i = n; i >= 1; i--) { while(a[i] <= a[R[i] + 1]) R[i] = R[R[i] + 1]; } LL ans = -1, l, r; for(int i = 1; i <= n; i++) { LL T = a[i] * (sum[R[i]] - sum[L[i] - 1]); if(ans < T) ans = T, l = L[i], r = R[i]; } printf("%lld\n%lld %lld\n", ans, l, r); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator