Pagini recente » Junior Challenge 2008, Clasament | Cod sursa (job #2515047) | Cod sursa (job #2353195) | Cod sursa (job #2114977) | Cod sursa (job #2813094)
#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;
}