![在这里插入图片描述](https://img-blog.csdnimg.cn/20200804205713166.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2Jid3FzYg==,size_16,color_FFFFFF,t_70)
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<math.h>
#include<algorithm>
#include<map>
#include<cstring>
#include<set>
using namespace std;
const int maxn = 10001;
int a[maxn], dp[maxn], s[maxn];
int main()
{
int n; cin >> n;
bool flag = false;
for (int i = 0; i < n; i++)
{
cin >> a[i];
if (a[i] >= 0)
flag = true;
}
if (flag == false)
{
cout << "0 " << a[0] <<" "<< a[n - 1]<< endl;
return 0;
}
dp[0] = a[0];
for (int i = 1; i < n; i++)
{
if (dp[i - 1] + a[i] > a[i])
{
dp[i] = dp[i - 1] + a[i];
s[i] = s[i - 1];
}
else
{
dp[i] = a[i];
s[i] = i;
}
}
int k = 0;
for (int i = 1; i < n; i++)
{
if (dp[i] > dp[k])
k = i;
}
cout << dp[k] << " " << a[s[k]] << " " << a[k] << endl;
return 0;
}