Cod sursa(job #280900)
Utilizator | Data | 13 martie 2009 17:27:25 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.29 kb |
#include<fstream.h>
int s,n,i,k,x,u,p,max=-2000000000;
int main()
{
ifstream f("ssm.in");
ofstream g("ssm.out");
f>>n;
for(i=0;i<n;i++)
{
f>>x;
if(s<0)
{
k=i;
s=0;
}
s+=x;
if(s>max)
{
max=s;
p=k;
u=i;
}
}
g<<max<<" "<<p+1<<" "<<u+1;
return 0;
}