Cod sursa(job #307454)

Utilizator andrici_cezarAndrici Cezar andrici_cezar Data 24 aprilie 2009 10:29:00
Problema Subsecventa de suma maxima Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.44 kb
#include<fstream.h>

long long n,i,c,y,s,yy,x,xx,max;

int main()
{
ifstream f("ssm.in");
ofstream g("ssm.out");
f>>n;
x=1;
for (i=1;i<=n;i++)
	{
	f>>c;
	if (s>=0)
		{y++;
		s+=c;
		if (s>max)
			{
			max=s;
			xx=x;
			yy=y;
			}
		}
	 else {
	       if (s>max)
			{
			max=s;
			yy=y;
			xx=x;
			}
	       s=c;
	       x=y++;
	       yy=y;
	      }
	 }
g<<max<<' '<<xx<<' '<<yy<<'\n';
g.close();
return 0;
}