Pagini recente » Cod sursa (job #731229) | Cod sursa (job #1542717) | Cod sursa (job #793312) | Cod sursa (job #1243136) | Cod sursa (job #486229)
Cod sursa(job #486229)
#include <fstream>
using namespace std;
const char InFile[]="oo.in";
const char OutFile[]="oo.out";
const int MaxN=100010;
ifstream fin(InFile);
ofstream fout(OutFile);
int v[MaxN],best[MaxN],n,val;
int main()
{
fin>>n;
for(register int i=1;i<=n;++i)
{
fin>>v[i];
}
fin.close();
best[0]=0;
best[1]=0;
best[2]=v[1]+v[2];
for(register int i=3;i<=n-1;++i)
{
best[i]=max(best[i-1],v[i]+v[i-1]+best[i-3]);
val=max(best[i],val);
}
best[0]=0;
best[1]=0;
best[2]=0;
for(register int i=3;i<=n-1;++i)
{
best[i]=max(best[i-1],v[i]+v[i-1]+best[i-3]);
val=max(best[i],val);
}
best[0]=0;
best[1]=v[1]+v[n];
best[2]=max(v[1]+v[2],best[1]);
for(register int i=3;i<=n-2;++i)
{
best[i]=max(best[i-1],v[i]+v[i-1]+best[i-3]);
val=max(best[i],val);
}
fout<<val;
fout.close();
return 0;
}