Pagini recente » Cod sursa (job #585725) | Cod sursa (job #2965549) | Cod sursa (job #1058996) | Cod sursa (job #1517628) | Cod sursa (job #3195919)
#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 long cost[nmax];
int cost_max=INT_MIN;
int ind_start;
int ind_stop;
int main()
{
f >> n;
for(int i = 1;i<=n;i++)
{
f >> v[i];
cost[i] = v[i] + cost[i-1];
}
int st=1,dr=n;
for(int i = 1;i<=n;i++)
{
for(int j = i+1;j<=n;j++)
{
if(cost[j] - cost[i] + v[i] > cost_max)
{
cost_max = cost[j] - cost[i] + v[i];
ind_start = i;
ind_stop = j;
}
}
}
g << cost_max << '\n' << ind_start << ' ' << ind_stop;
return 0;
}