Pagini recente » Cod sursa (job #208179) | Cod sursa (job #101338) | Cod sursa (job #259910) | Cod sursa (job #1015441) | Cod sursa (job #672737)
Cod sursa(job #672737)
#include<iostream>
#include<fstream>
using namespace std;
ifstream f("oo.in");
ofstream g("oo.out");
int a[100003],v[100003],s;
int max(int c, int d)
{
if(c>d) return c;
else
return d;
}
void rez(int x, int y)
{
v[x-2]=0;
v[x-1]=a[x-1]+a[x-2];
for(int i=x;i<=y;i++)
{
v[i]=max(v[i-1], v[i-3]+a[i]+a[i-1]);
s=max(s,v[i]);
}
}
int main()
{
int i,n;
f>>n;
for(i=1;i<=n;i++)
f>>a[i];
a[n+1]=a[1];
rez(3,n-1);
rez(4,n);
rez(5,n+1);
g<<s<<'\n';
return 0;
}