Cod sursa(job #300755)

Utilizator jupanubv92Popescu Marius jupanubv92 Data 7 aprilie 2009 17:37:47
Problema Secv Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.47 kb
#include<stdio.h>

int a[200001],n;

int main()
{
	freopen("suma2.in","r",stdin);
	freopen("suma2.out","w",stdout);
	scanf("%d",&n);
	int x=-1000000,y=-1000000;
	if(n>=1) scanf("%d",&x);
	if(n>=2) scanf("%d",&y);
	int best=x,max=x;
	if(best<y) best=y;
	a[1]=x;a[2]=y;
	for(int i=3;i<=n;i++)
	{	
		scanf("%d",&x);
		if(max<a[i-2]) max=a[i-2];
		a[i]=x;
		if(a[i]+max>a[i])
			a[i]=a[i]+max;
		if(a[i]>best) best=a[i];
	}
	printf("%d\n",best);
	return 0;
}