Cod sursa(job #2883316)
| Utilizator | Data | 1 aprilie 2022 13:32:15 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.64 kb |
#include <bits/stdc++.h>
using namespace std;
int main() {
ifstream cin("ssm.in");
ofstream cout("ssm.out");
int x;
int n;
cin >> n;
int smax = 1 << 31;
int pmax = 0, qmax = 0;
int sum = 0;
int p = 0, q = 0;
for (int i = 1; i <= n; ++i) {
cin >> x;
if (sum < 0) {
sum = x;
p = i;
} else {
sum += x;
}
if (sum > smax) {
smax = sum;
pmax = p;
qmax = i;
}
}
cout << smax << " " << pmax << " " << qmax << endl;
return 0;
}