Pagini recente » Cod sursa (job #223493) | Cod sursa (job #1568360) | Cod sursa (job #1072639) | Cod sursa (job #647437) | Cod sursa (job #3196147)
#include <iostream>
#include <fstream>
#include <climits>
#include <algorithm>
#include <vector>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int n;
const int nmax = 6000005;
int cost_min;
int cost_max = INT_MIN;
int ind_start;
int ind_stop;
long sum;
int indice;
int main()
{
f >> n;
int nr;
for (int i = 1; i <= n; i++)
{
f >> nr;
sum += nr;
if (cost_max < sum - cost_min)
{
ind_start = indice + 1;
ind_stop = i;
cost_max = sum - cost_min;
}
if (cost_min > sum)
{
indice = i;
cost_min = sum;
}
}
g << cost_max << ' ' << ind_start << ' ' << ind_stop;
return 0;
}