Pagini recente » Cod sursa (job #758324) | Cod sursa (job #2768746) | Cod sursa (job #1234029) | Cod sursa (job #2121427) | Cod sursa (job #2669642)
#include <bits/stdc++.h>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int n, x, i1, i2, s;
int nmx, smx, imx, i1mx, i2mx;
int main() {
f >> n;
i1 = 1;
i2 = 1;
nmx = -200100;
s = -1;
for (int i = 1; i <= n; i++) {
f >> x;
i2 = i;
if (x > nmx) {
nmx = x;
imx = i;
}
if (s < 0) {
s = 0;
s += x;
i1 = i;
if (s > smx) {
smx = s;
i1mx = i1;
i2mx = i2;
}
} else {
s += x;
if (s > smx) {
smx = s;
i1mx = i1;
i2mx = i2;
}
}
}
if (nmx < 0) {
g << nmx << " " << imx << " " << imx;
} else {
g << smx << " " << i1mx << " " << i2mx;
}
return 0;
}