Cod sursa(job #3339235)
| Utilizator | Data | 7 februarie 2026 10:36:23 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.61 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n, x;
in >> n;
long long smax = -2000000000;
long long scrrnt = -1;
int bmax = 0, emax = 0, bcur = 1;
for (int i = 1; i <= n; i++) {
fin >> x;
if (scrrnt < 0) {
scrrnt = x;
bcur = i;
} else {
scrrnt += x;
}
if (scrrnt > smax) {
smax = scrit;
bmax = bcur;
emax = i;
}
}
fout << smax << " " << bmax << " " << emax;
return 0;
}