Cod sursa(job #837294)

Utilizator Stefex09Stefan Teodorescu Stefex09 Data 17 decembrie 2012 19:49:38
Problema Oo Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream in ("oo.in");
ofstream out ("oo.out");

const int MAXN = 100010;
int V[MAXN], Best[MAXN];

inline int _max (const int &A, const int &B)
{
	if (A > B)
		return A;
	
	return B;
}

int main ()
{
	int N, i, Ans = 0;
	
	in >> N;
	
	for (i = 1; i <= N; i ++)
		in >> V[i];
	V[N + 1] = V[1];
	
	Best[2] = V[1] + V[2];
	for (i = 3; i <= N; i ++)
		Best[i] = _max (Best[i - 1], V[i] + V[i - 1] + Best[i - 3]);
	Ans = _max (Ans, Best[N]);
	cout << Ans << "\n";
	
	Best[2] = 0;
	Best[3] = V[2] + V[3];
	for (i = 4; i <= N; i ++)
		Best[i] = _max (Best[i - 1], V[i] + V[i - 1] + Best[i - 3]);
	Ans = _max (Ans, Best[N]);
	cout << Ans << "\n";
	
	Best[1] = 0, Best[2] = 0, Best[3] = 0, Best[4] = V[3] + V[4];
	for (i = 5; i <= N + 1; i ++)
		Best[i] = _max (Best[i - 1], V[i] + V[i - 1] + Best[i - 3]);
	Ans = _max (Ans, Best[N + 1]);
	
	out << Ans;
	
	return 0;
}