hdu1003 Max Sum(最大子序列)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<stdio.h> const int N=100005; typedef int T; T dat[N]; int main(){ //freopen("in.txt","r",stdin); int t,n,index,i; scanf("%d",&t); for(index=1;index<=t;index++){ scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%d",dat+i); } T sum=0,ans=-0xfffffff,tem=1,start,end; for(i=1;i<=n;i++){ sum+=dat[i]; if(sum>ans){ ans=sum; start=tem; end=i; } if(sum<0){ sum=0; tem=i+1; } } printf("Case %d:\n",index); printf("%d %d %d\n",ans,start,end); if(index<t) printf("\n"); } return 0; }