Cod sursa(job #2708614)
| Utilizator | Data | 19 februarie 2021 09:21:32 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int main()
{
int n, smax = -2000000, sc = -1, p;
int stmax, drmax;
in >> n;
for (int i = 1; i <= n; i++) {
int x;
in >> x;
if (sc < 0) {
sc = x;
p = i;
}
else
sc += x;
if (sc > smax) {
stmax = p;
drmax = i;
smax = sc;
}
}
out << smax << " " << stmax << " " << drmax;
return 0;
}