Cod sursa(job #709299)
#include <fstream>
#define NMAx 100100
#define max(a,b) ((a)>(b)?(a):(b))
using namespace std;
int V[NMAx],Best[NMAx];
int N,Sol;
void solve(int A,int B) {
Best[A]=0;
Best[A+1]=V[A]+V[A+1];
for(int i=A+2;i<=B;i++) {
Best[i]=max(Best[i-1],Best[i-3]+V[i]+V[i-1]);
Sol=max(Sol,Best[i]);
}
}
void citire() {
ifstream in("oo.in");
in>>N;
for(int i=1;i<=N;i++)
in>>V[i];
in.close();
}
void afis() {
ofstream out("oo.out");
out<<Sol<<'\n';
out.close();
}
int main() {
citire();
V[N+1]=V[1];
solve(1,N-1);
solve(2,N);
solve(3,N+1);
afis();
return 0;
}