Cod sursa(job #2956447)
| Utilizator | Data | 19 decembrie 2022 16:04:57 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.65 kb |
#include <fstream>
using namespace std;
const int INF = 2e9;
int main()
{
ifstream in("ssm.in");
ofstream out("ssm.out");
int n, sc = -1, smax = -INF, st, stmax, drmax;
in >> n;
for (int i = 1; i <= n; i++)
{
int x_i;
in >> x_i;
if (x_i > sc + x_i)
{
sc = x_i;
st = i;
}
else
{
sc += x_i;
}
if (sc > smax)
{
smax = sc;
stmax = st;
drmax = i;
}
}
out << smax << " " << stmax << " " << drmax;
out.close();
in.close();
return 0;
}