Cod sursa(job #1893820)
| Utilizator | Data | 26 februarie 2017 01:38:46 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
#include <fstream>
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int pmax, lmax, smax;
int main() {
int n, x, s = -2000000000, l;
in >> n;
for (int i = 1; i <= n; ++i) {
in >> x;
if (x < s + x) {
s += x;
l++;
} else {
l = 1;
s = x;
}
if (s > smax) {
smax = s;
pmax = i;
lmax = l;
}
}
out << smax << " " << pmax - lmax + 1 << " " << pmax;
return 0;
}
