Pagini recente » Cod sursa (job #1761693) | Cod sursa (job #713425) | Cod sursa (job #2260250) | Cod sursa (job #2899761) | Cod sursa (job #2813091)
#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] + x < 0 ) {
dp[i] = x;
left = i;
}
else
dp[i] = dp[i - 1] + x;
if ( dp[i] > maxx ) {
maxx = dp[i];
left_bound = left;
right_bound = i;
}
}
fout << maxx << " " << left_bound << " " << right_bound;
return 0;
}