Problem Description:
AC Source:
This question examines the dynamic programming, the problem-solving idea: the traversal (but has the skill), is in the current I each and is negative, the direct choice starts with the first i+1, is in the current I each sum is positive, the first I may not be used as the beginning (because the former i+1 sum must be greater than the value of the first i+1)
#include "iostream" using namespace Std;int main () {int T, n, start, end, SUM, MAX, TMP; int a[100000]; scanf ("%d", &t); for (int i = 1; I <= t; i++) {if (i > 1) printf ("\ n"); scanf ("%d", &n); scanf ("%d", a); max = a[0]; Start = end = 0; for (int j = 1; j < N; j + +) {scanf ("%d", a+j); if (A[j] > max) {max = a[j]; Start = end = J; }} for (int j = 0; J < N; j + +) {if (A[j] >= 0) {s um = 0; TMP = j; for (int k = j; k < n; k++) {sum + = a[k]; if (Sum > Max) {max = sum; start = tmp; end = k; } if (sum >= 0) {j = k + 1; } else {break; }}}} printf ("Case%d:\n", i); printf ("%d%d%d\n", Max, start+1, end + 1); } return 0;}
HD-ACM algorithm Specialization series (+)--max Sum