Cod sursa(job #1549555)
Utilizator | Data | 12 decembrie 2015 14:38:26 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 85 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.6 kb |
#include <iostream>
#include <fstream>
std::ifstream fin("ssm.in");
std::ofstream fout("ssm.out");
int sumaMaxima = 0, s = 0, pozInit = 1, pozFin, n, aux;
int main(int argc, char *argv[]){
fin >> n;
for (int i = 1; i <= n; i++){
fin >> aux;
s += aux;
if (s > sumaMaxima){
pozFin = i;
sumaMaxima = s;
}else if (s < 0){
s = 0;
pozInit = i + 1;
}/*
if (s == 0){
pozInit = i;
}*/
}
fout << sumaMaxima << " " << pozInit << " " << pozFin;
return 0;
}