Cod sursa(job #434206)
Utilizator | Sorecau Catalin sorecau_catalin | Data | 5 aprilie 2010 12:56:35 |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <fstream>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int S, Smax = -9999999, n, x, inc, sf, I;
int main()
{
fin >> n;
for ( int i = 1; i <= n; i++)
{
fin >> x;
S += x;
if ( S > Smax )
{
Smax = S;
inc = I;
sf = i;
}
if ( S < 0 )
{
S = 0;
I = i + 1;
}
}
fout << Smax << ' ' << inc << ' ' << sf;
fin.close();
fout.close();
return 0;
}