Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20272 Accepted Submission(s): 8973
1 #include<iostream> 2 #include<algorithm> 3 #include<cstdio> 4 #include<string.h> 5 using namespace std; 6 const int MAX = 10010; 7 int dp[MAX],a[MAX]; 8 int main() 9 { 10 int i,j,n,left,right,maxn,flag,num; 11 while(~scanf("%d",&n)) 12 { 13 num=0; 14 if(n==0) 15 break; 16 for(i=0;i<n;i++) 17 scanf("%d",&a[i]); 18 maxn=a[0]; 19 left=right=a[0]; 20 for(i=0;i<n;i++) 21 { 22 if(num<0) 23 { 24 num=a[i]; 25 flag=a[i]; 26 } 27 else 28 { 29 num+=a[i]; 30 } 31 if(num>maxn) 32 { 33 maxn=num; 34 left=flag; 35 right=a[i]; 36 } 37 } 38 if(maxn<0) 39 { 40 printf("0 %d %d\n",a[0],a[n-1]); 41 continue; 42 } 43 else 44 printf("%d %d %d\n",maxn,left,right); 45 } 46 return 0; 47 }
原文:http://www.cnblogs.com/caterpillarofharvard/p/4230116.html