Pagini recente » Cod sursa (job #794171) | Cod sursa (job #74133) | Cod sursa (job #2446386) | Cod sursa (job #711996) | Cod sursa (job #1152730)
#include <fstream>
#include <vector>
#define in "oo.in"
#define out "oo.out"
std :: ifstream f(in);
std :: ofstream g(out);
int N, best_ans;
std :: vector < int > V;
class Oo
{
public :
int compute(int Beg, int End)
{
std :: vector < int > Best(N + 1);
Best[Beg] = 0, Best[Beg + 1] = V[Beg] + V[Beg + 1];
for(int i = Beg + 2; i <= End; ++i)
Best[i] = std :: max(Best[i - 1], V[i] + V[i - 1] + (i - 3 >= 0 ? Best[i - 3] : 0));
return Best[End];
}
};
int main()
{
f >> N;
for(int x, i = 1; i <= N; ++i) f >> x, V.push_back(x);
V.push_back(V[0]);
Oo chicken;
best_ans = std :: max(best_ans, chicken.compute(0, N - 2));
best_ans = std :: max(best_ans, chicken.compute(1, N - 1));
best_ans = std :: max(best_ans, chicken.compute(2, N));
g << best_ans << '\n';
g.close();
return 0;
}