标签:
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn = 100010; const int inf = 0x3f3f3f3f; int a[maxn],dp[maxn]; int T,n; int main() { scanf("%d",&T); for(int cas = 1; cas <= T; cas++){ scanf("%d",&n); for(int i = 1; i <= n ;i++){ scanf("%d",&a[i]); dp[i] = a[i]; } for(int i = n-1; i >= 1; i--){ dp[i] = max(dp[i], dp[i+1] + a[i]); } // for(int i = 1; i <= n; i++) // printf("%d ",dp[i]); int index; int max1 = -inf; for(int i = 1; i <= n ;i++){ if(max1 < dp[i]){ max1 = dp[i]; index = i; } } int res = 0; int index1; for(int i = index; i <= n; i++){ res += a[i]; if(res == max1){ index1 = i; break; } } printf("Case %d:\n",cas); printf("%d %d %d\n",max1,index,index1); if(cas < T) printf("\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zero-begin/p/4520026.html