杭电OJ--1003题C++实现
#include<iostream>
using namespace std;
int a[100000];
void solve(int k,int n,int t);
int main()
{
int t,n;
cin>>t;
for(int i=1;i<=t;i++)
{
cin>>n;
for(int j=0;j<n;j++)
cin>>a[j];
solve(i,n,t);
}
return 0;
}
void solve(int k,int n,int t)
{
int sum=0,max_num=-1000,end_tag,start_tag=1,temp=1;
for(int i=0;i<n;i++)
{
sum+=a[i];
if(sum>max_num)
{
max_num = sum;
start_tag = temp;
end_tag = i+1;
}
if(sum<0)//这个地方是最为关键的地方
{
temp=i+2;
sum=0;
}
}
cout<<"Case "<<k<<":"<<endl;
if(k!=t)
cout<<max_num<<" "<<start_tag<<" "<<end_tag<<endl<<endl;
else
cout<<max_num<<" "<<start_tag<<" "<<end_tag<<endl;
}