Cod sursa(job #2051819)
Utilizator | StanCatalin StanCatalin | Data | 29 octombrie 2017 16:33:50 |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.62 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int main()
{
int s, smax, i, x, n, st, stmax, drmax;
in >> n;
in >> x;
s = smax = x;
stmax = drmax = st = 1;
if (s<0)
{ s = 0;
st = 2;
}
for (i=2; i<=n; i++)
{
in >> x;
s = s+x;
if (s>smax)
{ smax = s;
stmax = st;
drmax = i;
}
if (s<0)
{ s = 0;
st = i+1;
}
}
out << smax << " " << stmax << " " << drmax << "\n";
return 0;
}