Cod sursa(job #1474622)
Utilizator | Mereu Alexandra Alexandraaaa | Data | 22 august 2015 14:36:00 |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 90 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.48 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int main(){
int n, i, k, x, imax, jmax;
int s, smax;
f >> n;
i = imax = jmax = 1;
f >> s;
smax = s;
for (k = 2; k <= n; ++k){
f >> x;
s += x;
if (s <= 0){
i = k+1;
s = 0;
}
if (s > smax) {
smax = s;
imax = i;
jmax = k;
}
}
g << smax << " " << imax << " " << jmax;
f.close();
g.close();
return 0;
}