# 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 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)