杭电1003 最大连续子串
6 -1 5 4 -7
#include<iostream> using namespace std; int main(){ int t,n,a,max,sum,start,end,temp; while(cin>>t){ for(int i=1;i<=t;i++){ cin>>n; max=-1001; temp=1; sum=0; for(int i=1;i<=n;i++){ cin>>a; sum+=a; if(max<sum){ max=sum; start=temp; end=i; } if(sum<0){ temp=i+1; sum=0; } } cout<<"Case "<<i<<":"<<endl; cout<<max<<" "<<start<<" "<<end<<endl; if(i<t) cout<<endl; } } return 0; }