Cod sursa(job #2940147)
| Utilizator | Data | 14 noiembrie 2022 21:47:27 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include <iostream>
#include <fstream>
using namespace std;
int v[6000005];
ifstream in("ssm.in");
ofstream out("ssm.out");
int main()
{
int n, i, probpoz = 1, pozst, pozdr;
long long s = 0, smax;
smax = -4294967296;
in >> n;
for(i = 1; i <= n; i++){
in >> v[i];
if(s < 0){
s = 0;
probpoz = i;
}
s += v[i];
if(s > smax){
smax = s;
pozst = probpoz;
pozdr = i;
}
}
out << smax << " " << pozst << " " << pozdr;
return 0;
}
