Pagini recente » Cod sursa (job #797514) | Istoria paginii runda/superboolaneala/clasament | Cod sursa (job #1172809) | Cod sursa (job #2052565) | Cod sursa (job #2813092)
#include <iostream>
#include <fstream>
using namespace std;
using ll = long long;
const int NMAX = 6e6;
const long long INF = 1e18;
ll dp[1 + NMAX];
ifstream fin ( "ssm.in" );
ofstream fout ( "ssm.out" );
int main()
{
int n; fin >> n;
int left = 1; ll maxx = -INF;
int left_bound, right_bound;
for ( int i = 1; i <= n; i ++ ) {
int x; fin >> x;
if ( dp[i - 1] > 0 )
dp[i] = dp[i - 1] + x;
else {
left = i;
dp[i] = x;
}
if ( dp[i] > maxx ) {
maxx = dp[i];
left_bound = left;
right_bound = i;
}
}
fout << maxx << " " << left_bound << " " << right_bound;
return 0;
}