题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1231
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=10000+5;
const int INF=0x3f3f3f3f;
int n[maxn],d[maxn];
int main()
{int N,L,R,sum;while(cin>>N,N){memset(d,0,sizeof(d));int cnt=0;for(int i=1;i<=N;i++){scanf("%d",&n[i]);cnt+=n[i]<0;}if(cnt==N) {putchar('0');cout<<' '<<n[1]<<' '<<n[N]<<endl;continue;}for(int i=1;i<=N;i++)d[i]=max(d[i-1]+n[i],n[i]);R=max_element(d+1,d+1+N)-d;for(L=R,sum=d[R]-n[R];sum&&L>=1;--L,sum-=n[L]);cout<<d[R]<<' '<<n[L]<<' '<<n[R]<<endl;}return 0;
}