

二. 思路

三. 代码
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
const int N=1e4+10, INF=2e9;
int n;
int a[N];
class DP
{
public:
int f[N];
int maxv, lm, rm;
public:
DP()
{
initIO();
}
void initIO()
{
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
}
void work()
{
maxv=-INF, lm=1, rm=n;
int lt=1, rt;
for(int i=1;i<=n;++i)
{
//f[i]=max(0, f[i-1])+a[i];
if(f[i-1]<0) f[i]=a[i], lt=rt=i;
else f[i]=f[i-1]+a[i], rt=i;
if(f[i]>maxv) lm=lt, rm=rt, maxv=f[i];
}
if(maxv<0) maxv=0, lm=1, rm=n;
}
}dp;
int main()
{
cin>>n;
for(int i=1;i<=n;++i)
cin>>a[i];
dp.work();
cout<<dp.maxv<<" "<<a[dp.lm]<<" "<<a[dp.rm];
}