Cod sursa(job #2959239)
| Utilizator | Data | 30 decembrie 2022 12:11:46 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 95 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.69 kb |
#include <fstream>
using namespace std;
int main()
{
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n, smax, x, inceputBest, sfarsitBest, inceput, s, prev;
fin >> n;
smax = 0;
prev = -1;
for(int i = 0; i < n; i++){
fin >> x;
if(i == 0 || prev < 0){
s = x;
inceput = i + 1;
}
else{
s = prev + x;
if(s > smax){
smax = s;
inceputBest = inceput;
sfarsitBest = i + 1;
}
}
prev = s;
}
fout << smax << " " << inceputBest << " " << sfarsitBest;
return 0;
}
