6 -2 11 -4 13 -5 -2 10 -10 1 2 3 4 -5 -23 3 7 -21 6 5 -8 3 2 5 0 1 10 3 -1 -5 -2 3 -1 0 -2 0
20 11 13 10 1 4 10 3 5 10 10 10 0 -1 -2 0 0 0
#include<iostream> #include<cstring> using namespace std; #define M 100005 int a[M]; int main() { int n; while(~scanf("%d",&n) && n) { int ans,max,i,x1,y1,p,k=0; scanf("%d",a+1); if(a[1]<0) k++; ans=max=a[1]; x1=y1=p=1; for(i=2;i<=n;i++) { scanf("%d",a+i); if(a[i]<0) k++; if(ans<0) ans=a[i],p=i; else ans+=a[i]; if(max<ans) max=ans,x1=p,y1=i; } if(k==n) printf("%d %d %d\n",0,a[1],a[n]); else printf("%d %d %d\n",max,a[x1],a[y1]); } return 0; }
HDUJ 1231 最大连续子序列,布布扣,bubuko.com
原文地址:http://blog.csdn.net/hyccfy/article/details/38301419