Cod sursa(job #3262914)
| Utilizator | Data | 12 decembrie 2024 10:16:31 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.71 kb |
#include <fstream>
#include <climits>
using namespace std;
int main()
{
ifstream in("ssm.in");
ofstream out("ssm.out");
int n, st_i, st_max, dr_max, sc_i = -1, s_max = INT_MIN;
in >> n;
for (int i = 1; i <= n; i++)
{
int x_i;
in >> x_i;
if (x_i > sc_i + x_i)///echivalent cu 0 > sc_i
{
sc_i = x_i;
st_i = i;
}
else
{
sc_i += x_i;
}
if (sc_i > s_max)
{
s_max = sc_i;
st_max = st_i;
dr_max = i;
}
}
out << s_max << " " << st_max << " " << dr_max;
in.close();
out.close();
return 0;
}
