标签:
#include<stdio.h> #include<string.h> #define maxn 10010 int a[maxn],dp[maxn]; int main() { int n,i,j,max,flag,l,r,fl; while(scanf("%d",&n)!=EOF) { if(n==0) break; flag=0; memset(dp,0,sizeof(dp)); for(i=1;i<=n;i++) { scanf("%d",&a[i]); if(a[i]>=0) flag=1; } max=-99999999; l=r=fl=1; for(i=1;i<=n;i++) { if(dp[i-1]+a[i]>=a[i]) { dp[i]=dp[i-1]+a[i]; } else { fl=i; dp[i]=a[i]; } if(dp[i]>max) { l=fl; r=i; max=dp[i]; } } if(!flag) printf("0 %d %d\n",a[1],a[n]); else printf("%d %d %d\n",max,a[l],a[r]); } }
标签:
原文地址:http://www.cnblogs.com/sweat123/p/4735865.html