Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 190377 Accepted Submission(s): 44335
1 #include<iostream> 2 #include<cstdio> 3 int max(int x,int y ) 4 { 5 if (x>y) 6 return x; 7 else 8 return y; 9 } 10 int main() 11 { 12 int T,n,a,s,sum,x,y,z; 13 while (~scanf("%d",&T)) 14 { 15 for (int o=1;o<=T;o++) 16 { 17 scanf("%d",&n); 18 z=1;s=0;sum=-1001;x=1,y=1; 19 for (int p=1;p<=n;p++) 20 { 21 scanf("%d",&a); 22 s+=a; 23 if(s>sum) 24 { 25 sum=s; 26 x=z; 27 y=p; 28 } 29 if(s<0) 30 { 31 s=0; 32 z=p+1; 33 } 34 } 35 printf("Case %d:\n",o); 36 printf("%d %d %d\n",sum,x,y); 37 if(o!=T) 38 puts(""); 39 } 40 } 41 return 0; 42 }
原文:http://www.cnblogs.com/xfjy/p/4982288.html