Cod sursa(job #2636270)
Utilizator | Data | 17 iulie 2020 13:57:14 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 90 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.61 kb |
#include <fstream>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n, s[6000005], st, curr, best, stmax, drmax;
void citire() {
fin >> n;
for(int i = 1; i <= n; i++)
fin >> s[i];
}
void solve() {
for(int i = 1; i <= n; i++) {
curr += s[i];
if(curr < 0) {
curr = 0;
st = i+1;
}
if(curr > best) {
best = curr;
stmax = st;
drmax = i;
}
}
}
int main() {
citire();
solve();
fout << best << ' ' << stmax << ' ' << drmax;
}