hdu-----1003-----Max Sum

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.

Sample Input
`25 6 -1 5 4 -77 0 6 -1 1 -6 7 -5`

Sample Output
`Case 1:14 1 4Case 2:7 1 6`

```#include

using namespace std;int main(){
int t,n,max,sum,start,end,i,j,tmp,lastStart;
while(cin>>t)
{
for(i=1; i<=t; i++)
{
cin>>n;
max=-1001;
sum= 0;
lastStart=1;
for(j=1; j<=n; j++)
{
cin>>tmp;
sum+=tmp;
if(sum> max)
{
start=lastStart;
end=j;
max = sum;
}
if(sum< 0)
{
lastStart = j+1;
sum= 0;
}
}
cout<<"Case "<
<<":"<

cout<

<

<

if(i!=t)
cout<

}
}
return 0;}

```

#### 最新留言

[***.36.148.77]2022年06月19日 20时20分51秒

## 关于作者

喝酒易醉，品茶养心，人生如梦，品茶悟道，何以解忧？唯有杜康！
-- 愿君每日到此一游！

## 最新文章

iPhone开发【二十四】数据持久化总结之第4篇—sqlite3数据库 2019-07-26 18:46:25
iPhone开发【二十三】常用IOS开源组件【第1篇】 2019-07-26 18:46:24
iPhone开发【二十二】数据持久化总结之第3篇—归档（NSKeyedArchiver、NSKeyedUnarchiver） 2019-07-26 18:46:24
iPhone开发【二十一】数据持久化总结之第2篇—属性文件（.plist） 2019-07-26 18:46:23
iPhone开发【二十】数据持久化总结之第1篇—NSUserDefaults 2019-07-26 18:46:23
iPhone开发【十九】XML解析之NSXMLParser（使用Web Services查询火车信息） 2019-07-26 18:46:22
iPhone开发【十八】自定义视图之ActionSheet中使用PickerView 2019-07-26 18:46:21

iPhone开发【十七】多线程开发之NSOperation&NSOperationQueue——异步下载图片 2019-07-26 18:46:20
iPhone开发【十六】实现点击一个UIImageView时打开键盘 2019-07-26 18:46:20