Cod sursa(job #2845481)
| Utilizator | Data | 7 februarie 2022 21:50:17 | |
|---|---|---|---|
| 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;
using ll = long long;
int main () {
ifstream f ("ssm.in");
ofstream g ("ssm.out");
int n; f >> n;
ll ant = 0;
ll mx = -1e18;
ll now = 0;
int st, stmx, drmx;
for(int i=1; i<=n; i++) {
ll x; f >> x;
if(x>ant+x) {
now = x;
ant = x;
st = i;
}
else {
now = ant + x;
ant = now;
}
if(now > mx) {
mx = now;
stmx = st;
drmx = i;
}
}
g << mx << " " << stmx << " " << drmx;
return 0;
}
