Pagini recente » Cod sursa (job #570868) | Cod sursa (job #1429560) | Cod sursa (job #3040047) | Cod sursa (job #455867) | Cod sursa (job #3195918)
#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;
while(st<=dr)
{
if(cost[dr] - cost[st] + v[st] > cost_max)
{
cost_max = cost[dr] - cost[st] + v[st];
ind_start = st;
ind_stop = dr;
}
if(v[st] + v[st+1] > v[dr] + v[dr-1])
{
dr--;
}else{
st++;
}
}
g << cost_max << '\n' << ind_start << ' ' << ind_stop;
return 0;
}