Cod sursa(job #280333)

Utilizator Bit_MasterAlexandru-Iancu Caragicu Bit_Master Data 13 martie 2009 12:27:38
Problema Subsecventa de suma maxima Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.47 kb
#include <stdio.h>

void calcul()
{
	long n,x,sc=0,smax=-1000000000,stc=1,drc,stmax,drmax;  
	scanf ("%ld",&n);
	for (long i = 1; i <= n; ++i)
	{
		scanf ("%ld",&x);
		sc += x;
		if (sc > smax)
		{
			smax = sc;
			stmax = stc;
			drmax = drc;
		}
		if (sc < 0)
		{
			sc = 0;
			stc = drc + 1;
		}
	}
	printf("%ld%ld%ld",smax,stmax,drmax);
}

int main()
{
	freopen ("ssp.in","r",stdin);
	freopen ("ssp.out","w",stdout);
	calcul();
	return 0;
}