Cod sursa(job #2651742)
| Utilizator | Data | 23 septembrie 2020 15:05:06 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 25 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.67 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream in("ssm.in");
ofstream out("ssm.out");
int n, i, x, maxAct = 0, firstAct = 0, last = 0, maxTotal = 0, firstTotal = 0;
in >> n;
for (i = 1; i <= n; i++)
{
in >> x;
if (maxAct + x >= 0)
{
maxAct += x;
}
if (maxAct > maxTotal)
{
firstTotal = firstAct;
maxTotal = maxAct;
last = i;
}
if (maxAct + x < 0)
{
firstAct = i + 1;
maxAct = 0;
}
}
out << maxTotal << " " << firstTotal << " " << last;
}
