Problem Descriptiongiven a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14. Inputthe first line of the input contains an integer T (1<=t<=20) which means the number of test cases. Then T lines follow, each line starts with a number N (1<=n<=100000), then n integers followed (all the integers is b etween-1000 and 1000). Outputfor Each test case, you should output of the lines. The first line was "Case #:", # means the number of the the test case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end posi tion of the sub-sequence. If there is more than one result, output the first one. Output a blank line between cases. Sample Input2 5 6-1 5 4-7 7 0 6-1 1-6 7-5 Sample outputcase 1:14 1 4 case 2:7 1 6
and the largest oldest sequence: #include<stdio.h>intMain () {intT, I, N, X, A, B, C, Sum, M, k =0, flag =0; scanf ("%d", &T); while(t--) {k++; scanf ("%d%d", &n, &x); Sum= M =x; A= b = c =1; for(i =2; I <= N; i++) {scanf ("%d", &x); if(Sum + x <x) {sum=x; A=i; } //if the sum+x is smaller than x, the sum is set to X, and the position of this time is recorded Elsesum+ = x;//Otherwise, directly add if(Sum >m) {m=sum; b=A; C=i; } //change the maximum and corresponding position when finding the and of a larger sub-sequence } if(Flag = =1) printf ("\ n"); printf ("Case %d:\n", K); printf ("%d%d%d\n", M, B, c); Flag=1; } return 0;}
HDU 1003 Max Sum