Cod sursa(job #2196425)
| Utilizator | Data | 19 aprilie 2018 11:30:58 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 80 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int main()
{
int n, x, st, dr, stm;
long s = 0, smax = 0;
fin >> n;
for(int i = 1; i <= n; i++) {
fin >> x;
if(x + s > x) {
s += x;
} else {
s = x;
st = i;
}
if(s > smax) {
smax = s;
stm = st;
dr = i;
}
}
fout << smax << " " << st << " " << dr;
return 0;
}
