http://acm.hdu.edu.cn/showproblem.php?pid=1003
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others) total submission (s): 216737 accepte D Submission (s): 51087
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
Recommendwe carefully selected several similar problems for you:1176 1087 1069 2084 1058
#include <cstdio>#include<cstring>#include<iostream>#include<cmath>#include<vector>#include<algorithm>using namespacestd;#definePI 3.1415926Const intmaxn=1000007;Const intinf=0x3f3f3f3f;intA[MAXN];intMain () {intT, cas=1, f=0; scanf ("%d", &T); while(t--) { if(f) puts ("");///printf ("\ n"); intN; scanf ("%d", &N); for(intI=1; i<=n; i++) scanf ("%d", &A[i]); intNows=1, start=1, end=1; intsum, Max; Sum=max=a[1]; for(intI=2; i<=n; i++) { if(sum+a[i]<A[i]) {Sum=A[i]; Nows=i; } Elsesum+=A[i]; if(sum>Max) {Max=sum; Start=nows; End=i; }} printf ("Case %d:\n%d%d%d\n", cas++, Max, Start, End); F=1; } return 0;}
HDU---1003---Max Sum