hdu 1003 Max Sum
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1003
代码:
View Code
1 #include<stdio.h> 2 int a[100010]; 3 int main() 4 { 5 int t,n,i,k; 6 int thissum,maxsum,xt,x,yt; 7 scanf("%d",&t); 8 for(k=1;k<=t;k++) 9 { 10 scanf("%d",&n); 11 for(i=0;i<n;i++) 12 { 13 scanf("%d",&a[i]); 14 } 15 thissum=0; 16 maxsum=-99999; 17 x=1; 18 yt=1; 19 for(i=0;i<n;i++) 20 { 21 thissum+=a[i]; 22 if(thissum>maxsum) 23 { 24 maxsum=thissum; 25 xt=x; 26 yt=i+1; 27 } 28 if (thissum<0) 29 { 30 thissum=0; 31 x=i+2; 32 } 33 } 34 printf("Case %d:\n",k); 35 printf("%d %d %d\n",maxsum,xt,yt); 36 if(k!=t) 37 printf("\n"); 38 } 39 return 0; 40 }