Pagini recente » Cod sursa (job #1724623) | Cod sursa (job #2100330) | Cod sursa (job #858872) | Cod sursa (job #702629) | Cod sursa (job #2844795)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int nmax = 6e6;
ll v[nmax+5];
ll best[nmax+5];
int st[nmax+5];
int main () {
ifstream f ("ssm.in");
ofstream g ("ssm.out");
int n; f >> n;
for(int i=1; i<=n; i++) f >> v[i];
ll ans = -1e18;
int l, r;
for(int i=1; i<=n; i++) {
if(v[i] > best[i-1]+v[i]) {
st[i] = i;
best[i] = v[i];
}
else {
st[i] = st[i-1];
best[i] = best[i-1] + v[i];
}
if(best[i] > ans) {
ans = best[i];
l = st[i];
r = i;
}
}
g << ans << " " << l << " " << r;
return 0;
}