Cod sursa(job #2017993)

Utilizator otto1Palaga Vicentiu-Octavian otto1 Data 3 septembrie 2017 11:52:08
Problema Oo Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.38 kb
#include<fstream>
using namespace std;
int n,v[100002];
ifstream f("oo.in");
ofstream g("oo.out");
int fct(int x,int y)
{int w[100002];
w[x]=0;
w[x+1]=v[x]+v[x+1];
for(int 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()
{f>>n;
for(int i=1;i<=n;i++)
f>>v[i];
v[0]=v[n];
v[n+1]=v[1];
g<<max(fct(1,n-1),max(fct(2,n),fct(3,n+1)));
return 0;
}