Cod sursa(job #1435453)
Utilizator | Data | 13 mai 2015 11:23:30 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 90 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int n, x, s, st, stmax, drmax, maxim = -2000001, i;
int main()
{
f >> n;
for (i = 1; i <= n; i++)
{
f >> x;
if (s+x > 0)
s += x;
else
s = 0, st = i+1;
if (s > maxim)
maxim = s, stmax = st, drmax = i;
}
g << maxim << " " << stmax << " " << drmax;
return 0;
}