Water ~
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 5 using namespace std; 6 const int INF=100000000; 7 8 int t,n,a; 9 int main() 10 { 11 cin>>t; 12 for(int i=1;i<=t;i++){ 13 cin>>n; 14 int sum=0; 15 int max=-INF; 16 int l=1,left=1,right=1; 17 18 for(int j=1;j<=n;j++){ 19 cin>>a; 20 sum+=a; 21 if(sum>max){ 22 right=j; 23 left=l; 24 max=sum; 25 } 26 else if(sum<0){ // can not be "else if" ! 27 sum=0; 28 l=j+1; 29 } 30 } 31 if(i!=1)printf(" "); 32 printf("Case %d: ",i ); 33 printf("%d %d %d ",max,left,right ); 34 } 35 return 0; 36 }