Pagini recente » Cod sursa (job #2485216) | Cod sursa (job #2420148) | Cod sursa (job #303249) | Cod sursa (job #2598481) | Cod sursa (job #832512)
Cod sursa(job #832512)
#include <cstdio>
using namespace std;
#define maxn 100005
int v[maxn];
int best[maxn];
inline int max(int a,int b)
{
if(a>=b)
return a;
return b;
}
int main()
{
freopen("oo.in","r",stdin);
freopen("oo.out","w",stdout);
int N,i;
scanf("%d",&N);
for(i=1;i<=N;++i)
scanf("%d",v+i);
v[N+1]=v[1];
int show;
best[2] = v[2]+v[1];
for(i=3;i<N;++i)
best[i] = max(best[i-1],v[i]+v[i-1]+ best[i-3]);
show = best[N-1];
best[2] = 0;
best[3] = v[3]+v[2];
for(i=4;i<=N;++i)
best[i] = max(best[i-1],v[i]+v[i-1]+ best[i-3]);
show = max(show,best[N]);
best[3] = 0;
best[4] = v[4] + v[3];
for(i=5;i<=N+1;++i)
best[i] = max(best[i-1],v[i]+v[i-1]+ best[i-3]);
show = max(show,best[N+1]);
printf("%d\n",show);
return 0;
}