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