原题:
Description
Input
Output
Sample Input
Sample Output
#include <iostream> #include<cstdio> using namespace std; int main() { int j, i, k, n, m, t; int a; scanf("%d", &t); for (j = 1; j <= t; j++) { scanf("%d", &n); int sum = 0, maxsum = -1001, first = 0, last = 0, temp = 1; for (i = 0; i<n; i++) { scanf("%d", &a); sum += a; if (sum > maxsum) { maxsum = sum; first = temp; last = i + 1; } if (sum < 0) { sum = 0; temp = i + 2; } } printf("Case %d:\n%d %d %d\n", j, maxsum, first, last); if (j != t) { printf("\n"); } } return 0; }
原文:http://www.cnblogs.com/shawn-ji/p/4732758.html