Cod sursa(job #3249099)
| Utilizator | Data | 14 octombrie 2024 19:13:12 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 90 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.65 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 or (s == smax and poz < pozmax) or (s == smax and poz == pozmax and l < lmax)){
smax = s;
lmax = l;
pozmax = poz;
}
}
fout << smax << ' ' << pozmax << ' ' << pozmax + lmax - 1;
}
