Cod sursa(job #3198849)
Utilizator | Iuhas Florin florinul1 | Data | 30 ianuarie 2024 19:21:37 |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 95 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <fstream>
#include <iostream>
using namespace std;
int n, smax = (1 << 31), startmax, stopmax;
int main()
{
ifstream fin("ssm.in");
int i, x, sc = 0, stc = 1;
fin >> n;
for (i = 1; i <= n; i++) {
fin >> x;
if (sc <= 0) {
sc = 0;
stc = i;
}
sc += x;
if (sc > smax) {
smax = sc;
startmax = stc;
stopmax = i;
}
}
fin.close();
ofstream fout("ssm.out");
fout << smax << ' ' << startmax << ' ' << stopmax;
fout.close();
return 0;
}