Cod sursa(job #549339)

Utilizator BuRNB Radu BuRN Data 8 martie 2011 14:39:26
Problema Oo Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <fstream>
#include <algorithm>
using namespace std;

#define nmax 100001
int n, o[nmax];
int best[nmax], sol;

void citire()
{
	ifstream in("oo.in"); in>>n;
	for(int i=1; i<=n; i++)
		in>>o[i];
	o[0] = 0; o[n+1] = o[1];
}

void afisare()
{
	ofstream out("oo.out");
	out<<sol;
}

void solve(int pi, int ps)
{
	best[pi-2] = 0;
	best[pi-1] = o[pi-2]+o[pi-1];
	for(int i=pi; i<=ps; i++)
	{
		best[i] = max(best[i-1], best[i-3]+o[i-1]+o[i]);
		if(best[i] > sol)
			sol = best[i];
	}
}

int main()
{
	citire();
	solve(3, n-1);
	solve(4, n);
	solve(5, n+1);
	afisare();
	return 0;
}