Max Sum
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 82954 Accepted Submission(s): 19109
#include<iostream>
using namespace std;
int a[100001];
int main()
{
long n,max,sum,xi,x,y,k,m,i;
//long long n,max,sum,xi,x,y,k,m,i;
cin>>n;
for(k=1;k<=n;k++)
{
cin>>m;
max=-2;
if(k!=1)
cout<<endl;
for(i=0;i<m;i++)
cin>>a[i];
sum=-2;
for(i=0;i<m;i++)
{
if(sum>=0)
sum+=a[i];
else
{
sum=a[i];
xi=i;
}
if(sum>=max)
{
max=sum;
x=xi;
y=i;
}
}
cout<<"Case "<<k<<':'<<endl;
cout<<max<<' '<<x+1<<' '<<y+1<<endl;
}
return 0;
}