状态方程f[i]表示0~i最长子序列长度。
状态转移f[i]=max(f[i],f[i-1]+d[i])。
//
// main.cpp
// Richard
//
// Created by 邵金杰 on 16/9/8.
// Copyright © 2016年 邵金杰. All rights reserved.
//
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=10000+100;
int f[maxn];
struct node{
int begin,end;
node(int b=0,int e=0): begin(b),end(e) {}
}state[maxn];
int d[maxn];
int main()
{
int n;
int pos=0;
while(scanf("%d",&n)&&n)
{
int cnt=0,flag=-1;
memset(f,0,sizeof(f));
for(int i=0;i<n;i++){
scanf("%d",&d[i]);
if(d[i]==0) flag=i;
if(d[i]>0) {cnt++;f[i]=d[i];}
else f[i]=0;
}
if(cnt>0)
{
int MAX=f[0];
pos=0;
for(int i=0;i<n;i++) state[i]=node(i,i);
for(int i=1;i<n;i++)
{
if(f[i]<f[i-1]+d[i])
{
f[i]=f[i-1]+d[i];
state[i]=node(state[i-1].begin,i);
if(f[i]>MAX) {MAX=f[i];pos=i;}
}
}
cout<<f[pos]<<" "<<d[state[pos].begin]<<" "<<d[state[pos].end]<<endl;
}
else
{
if(flag!=-1)
cout<<"0 0 0"<<endl;
else
cout<<"0"<<" "<<d[0]<<" "<<d[n-1]<<endl;
}
}
return 0;
}