Cod sursa(job #1152730)

Utilizator mvcl3Marian Iacob mvcl3 Data 24 martie 2014 21:48:17
Problema Oo Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#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;
}