http://acm.hust.edu.cn/vjudge/contest/121397#problem/D
#include <stdio.h> #include <string.h> #define oo 0x3f3f3f3f #define maxn 11000 int main() { int n,a[maxn],x,y,z,ans,i,sum,f; while(scanf("%d",&n),n) { f=0; for(i=1; i<=n; i++) { scanf("%d",&a[i]); if(a[i]<0) f++; } if(f==n) printf("0 %d %d ",a[1],a[n]); else { ans=-oo; z=1; sum=0; for(i=1; i<=n; i++) { sum+=a[i]; if(sum>ans) { ans=sum; x=z; y=i; } if(sum<0) { z=i+1; sum=0; } } printf("%d %d %d ",ans,a[x],a[y]); } } return 0; }