Pagini recente » Cod sursa (job #2632263) | 2020 | Cod sursa (job #2752624) | Cod sursa (job #2183349) | Cod sursa (job #3195928)
#include <bits/stdc++.h>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int n;
const int nmax = 6000005;
int v[nmax];
long cost[nmax];
int cost_min=INT_MAX;
int cost_max=INT_MIN;
int ind_start;
int ind_stop;
int sum;
int main()
{
f >> n;
for(int i = 1;i<=n;i++)
{
f >> v[i];
sum+=v[i];
cost[i] = sum - cost[ind_start];
if(cost_min > cost[i] && v[i] > 0)
{
ind_start = i;
cost_min = cost[i];
}
if(cost_max < cost[i])
{
ind_stop = i;
cost_max = cost[i];
}
}
g << cost_max << ' ' << ind_start << ' ' << ind_stop;
return 0;
}