Cod sursa(job #1083199)
Utilizator | Data | 15 ianuarie 2014 18:41:05 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.53 kb |
# include <fstream>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int n,x,a,b,p,u,i;
long long s, smax;
int main()
{
f >> n;
f >> x;
s = x; smax = x; p=u=1;
for (i=2; i<=n; i++)
{
f >> x;
if (s + x < x)
{
s = x; p=u=i;
}
else
{
s=s+x; u++;
}
if (s > smax)
{
smax = s;
a = p; b = u;
}
}
g << s << " "<< a<<" "<<b <<"\n";
return 0;
}