# HDU 1003 Max Sum

#include <iostream>
#include <cstdio>
#define maxn 100010
using namespace std;
int T,N,a[maxn];

int main()
{
//freopen("in.txt","r",stdin);
int g=1,flag;
scanf("%d",&T);
while(T--)
{
int begin,end,t;
__int64 sum,maxsum;
begin=end=0;
scanf("%d",&N);
for(int i=0;i<N;i++)
{
scanf("%d",&a[i]);
}
sum=maxsum=a[0],flag=0,t=0;
for(int i=1;i<N;i++)
{
if(sum<0)
{
sum=a[i];
if(sum>maxsum)
{
maxsum=sum;
end=i;
}
t=0;
continue;
}
if(sum+a[i]<a[i])
sum=a[i];
else
{
sum+=a[i];
t++;
}
if(sum>maxsum)
{
maxsum=sum;
end=i;
flag=t;
}
}
begin=end-flag;
printf("Case %d:\n%I64d %d %d\n",g,maxsum,begin+1,end+1);
g++;
if(T)
printf("\n");
}
return 0;
}


Problem Description
Given 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.

Input
The 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 are between -1000 and 1000).

Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.

2
5 -3 -2 -1 -2 -3 ———— -1 3 3
-1 -2 -3 -4 -5 -6—————-1 1 1

#### 动态规划——Hdu_1003_Max Sum

2012-07-22 12:32:41

#### HDUOJ-1003 Max Sum(最大子序列和)(动态规划)

2016-04-30 14:48:39

#### HDU1003 Max Sum 最大子序列和的问题【四种算法分析+实现】

2014-05-18 21:08:59

#### hdu 1003 Max Sum(最大连续子序列和) （学了一下分治）

2014-07-17 13:03:47

#### Java - 杭电1003 Max Sum

2016-05-26 21:39:31

#### HDU 1003 MAX SUM java 实现

2014-07-20 17:47:28

#### HDU-1003 Max Sum （线性dp 最大连续和）

2017-11-12 20:24:55

#### 杭电oj-1003-Max Sum

2015-12-09 14:39:53

#### 杭电oj(java版)——1003 Max Sum

2017-04-11 21:01:06

#### 杭电OJ（HDOJ）1003题：Max Sum（动态规划）

2014-12-05 20:36:02