http://acm.hdu.edu.cn/showproblem.php?pid=1003
这道题主要求最大值
不难
我的代码:
#include<iostream>
using namespace std;
#include<cstdio>
int t,n,i,j;
int main()
{
int a;
cin>>t;
for(j=1;j<=t;j++)
{
cin>>n;
int f=0;
int s=1,e=1,k=1;
int max=-1001;
for(i=1;i<=n;i++)
{
cin>>a;
f+=a;
if(f>max)
{
max=f;
s=k;
e=i;
}
if(f<0)
{
k=i+1;
f=0;
}
}
printf("Case %d:\n",j);
printf("%d %d %d\n",max,s,e);
if(j!=t)
cout<<endl;
}
return 0;
}