Pagini recente » Cod sursa (job #1951317) | Cod sursa (job #586720) | Cod sursa (job #2029052) | Cod sursa (job #2692129) | Cod sursa (job #2813089)
#include <iostream>
#include <fstream>
using namespace std;
using ll = long long;
const int NMAX = 6e6;
ll dp[1 + NMAX];
ifstream fin ( "ssm.in" );
ofstream fout ( "ssm.out" );
int main()
{
int n; fin >> n;
int left = 1; ll maxx = -2e9;
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;
}