Cod sursa(job #2603030)
Utilizator | Alex Ben alex_benescu | Data | 18 aprilie 2020 14:10:32 |
---|---|---|---|
Problema | Oo | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.37 kb |
#import<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];
}
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)));
}