Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1003
Test instructions: Find out the maximum number of consecutive items.
Max Sum
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 192179 Accepted Submission (s): 44762
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 Input25 6-1 5 4-77 0 6-1 1-6 7-5
Sample outputcase 1:14 1 4Case 2:7 1 6
Authorignatius.l
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cstdlib>using namespacestd;Const intMAXN =100005;intMain () {intT, N, Max; scanf ("%d",&t); intk=1; while(t--) {scanf ("%d",&N); scanf ("%d",&Max); intsum =Max; ints=1, e=1, X; ints=1, e=1; for(intI=2; i<=n; i++) {scanf ("%d",&x); if(Sum+x <x) {sum=x; S=i; E=i; } Else{e=i; Sum= Sum +x; } if(Sum >Max) {Max=sum; S=s; E=e; }} printf ("Case %d:\n", k++); printf ("%d%d%d\n", max,s,e); if(t!=0) {printf ("\ n"); } } return 0;}
HDU 1003 Max Sum