Cod sursa(job #1474633)
Utilizator | Mereu Alexandra Alexandraaaa | Data | 22 august 2015 14:58:41 |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 95 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.5 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 && k<=n) {
f >> x;
k++;
i = k;
s = x;
}
if (s > smax) {
smax = s;
imax = i;
jmax = k;
}
}
g << smax << " " << imax << " " << jmax;
f.close();
g.close();
return 0;
}