Cod sursa(job #2832062)
| Utilizator | Data | 12 ianuarie 2022 18:48:10 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.66 kb |
#include <bits/stdc++.h> /* printf, scanf, puts, NULL */
#include <stdlib.h> /* srand, rand */
#include <time.h>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int main() {
int n, x, max = INT_MIN, start, finish, s = 0, startMax;
fin >> n;
for (int i = 1; i <= n; i ++) {
fin >> x;
if (s + x >= x) {
s += x;
}
else {
s = x;
start = i;
}
if (max < s) {
finish = i;
startMax = start;
max = s;
}
}
fout << max << ' ' << startMax << ' ' << finish;
return 0;
}
