Cod sursa(job #369336)
Utilizator | Data | 28 noiembrie 2009 07:36:19 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include <fstream>
int n, max = -2000000000, s, P, U, p, u, a;
int main() {
std::ifstream fi("ssm.in");
std::ofstream fo("ssm.out");
fi >> n;
for (u = 1; u <= n; u++) {
fi >> a;
if (s < 0) {
s = a; p = u;
} else
s += a;
if (s > max) {
max = s; P = p; U = u;
}
}
fo << max << ' ' << P << ' ' << U;
return 0;
}