Pagini recente » Cod sursa (job #1251839) | Cod sursa (job #2636749) | Cod sursa (job #2138020) | Cod sursa (job #960876) | Cod sursa (job #1567745)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
const int dmax = 6000000;
int a[dmax + 1];
int best[dmax + 1];
int bestSum;
int N;
int main()
{
int i, p_i, p_f;
in >> N;
for(i = 1; i <= N; i++) in >> a[i];
bestSum = a[1];
for(i = 1; i <= N; i++)
{
best[i] = a[i];
if(best[i] < best[i-1] + a[i]) best[i] = best[i-1] + a[i];
if(bestSum < best[i])
{
bestSum = best[i];
p_f = i;
}
}
//for(i = 1; i <= N; i++) cout << best[i] <<" ";
int s = 0;
for(i = p_f; i >= 1; i--)
{
s += a[i];
if(s == bestSum) p_i = i;
}
out << bestSum << " " << p_i << " " << p_f;
return 0;
}