Cod sursa(job #3249096)
Utilizator | Data | 14 octombrie 2024 19:09:40 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 95 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.58 kb |
#include<bits/stdc++.h>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n, x, s, smax, pozmax, lmax, poz, l;
int main(){
fin >> n;
poz = 1;
for(int i = 1; i <= n; ++i){
fin >> x;
if(s >= 0){
s = s + x;
++l;
}
else{
s = x;
poz = i;
l = 1;
}
if(s > smax){
smax = s;
lmax = l;
pozmax = poz;
}
}
fout << smax << ' ' << pozmax << ' ' << pozmax + lmax - 1;
}