Cod sursa(job #491484)

Utilizator Robert29FMI Tilica Robert Robert29 Data 11 octombrie 2010 16:12:04
Problema Oo Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include<stdio.h>
FILE*f=fopen("oo.in","r");
FILE*g=fopen("oo.out","w");
int max1,max2,i,n,x[100001];
char v[100001];
int main() {
	fscanf(f,"%d",&n);
	for(i=1;i<=n;i++)
		fscanf(f,"%d",&v[i]);
	x[2]=x[3]=v[1]+v[2];
	for(i=4;i<n;i++)
		if(x[i-1]>v[i]+v[i-1]+x[i-3])
			x[i]=x[i-1];
		else
			x[i]=v[i]+v[i-1]+x[i-3];
	max1=x[n-1];
	x[1]=x[2]=v[1]+v[n];
	for(i=3;i<n-1;i++)
		if(x[i-1]>v[i]+v[i-1]+x[i-3])
			x[i]=x[i-1];
		else
			x[i]=v[i]+v[i-1]+x[i-3];
	max2=x[n-2];
	x[1]=x[2]=0;
	for(i=3;i<=n;i++)
		if(x[i-1]>v[i]+v[i-1]+x[i-3])
			x[i]=x[i-1];
		else
			x[i]=v[i]+v[i-1]+x[i-3];
	if(max1<max2)
		max1=max2;
	if(max1<x[n])
		max1=x[n];
	fprintf(g,"%d",max1);
	
	fclose(g);
	fclose(f);
	return 0;
}