Cod sursa(job #2789276)

Utilizator BlaugranasEnal Gemaledin Blaugranas Data 27 octombrie 2021 11:58:18
Problema Oo Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.4 kb
#include<fstream>
using namespace std;
ifstream f("oo.in");
ofstream g("oo.out");
int n,v[100002],i;
int F(int x,int y)
{
    int i,w[100002];
    for(w[x]=0,w[x+1]=v[x]+v[x+1],i=x+2;i<=y;++i)
        w[i]=max(w[i-1],w[i-3]+v[i-1]+v[i]);
    return w[y];
}
int main()
{
    for(f>>n,i=1;i<=n;++i)
        f>>v[i];
    v[0]=v[n],v[n+1]=v[1],g<<max(F(1,n-1),max(F(2,n),F(3,n+1)));
    return 0;
}