Pagini recente » Cod sursa (job #2092121) | Cod sursa (job #162374) | Cod sursa (job #1582914) | Monitorul de evaluare | Cod sursa (job #2684530)
#include <fstream>
#include <climits>
using namespace std;
int main() {
int i, st, x, n, a, b, S = 0, Smax = LONG_MIN;
ifstream f("ssm.in");
f >> n;
st = 1;
for (i = 1; i <= n; i++) {
f >> x;
S = S + x;
if (S > Smax) {
Smax = S;
a = st;
b = i;
}
if (S < 0) {
S = 0;
st = i + 1;
}
}
f.close();
ofstream g("ssm.out");
g << Smax << ' ' << a << ' ' << b;
g.close();
return 0;
}