Cod sursa(job #3277840)
Utilizator | Data | 17 februarie 2025 15:05:24 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.6 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int main()
{
int sc_i = 0, st = 1, st_max = 1, dr_max = 1, s_max = INT_MIN;
int n, x;
f >> n;
for(int i = 1; i <= n; i++) {
f >> x;
if (sc_i < 0) {
sc_i = x;
st = i;
} else
sc_i += x;
if (sc_i > s_max) {
s_max = sc_i;
st_max = st;
dr_max = i;
}
}
g << s_max << " " << st_max << " " << dr_max;
return 0;
}