Cod sursa(job #2269292)

Utilizator Alex_BubBuburuzan Alexandru Alex_Bub Data 25 octombrie 2018 20:51:46
Problema Oo Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("oo.in");
ofstream fout("oo.out");

const int NMAX = 100000;

int V[NMAX + 5], DP[NMAX + 5], N, ans;

int main()
{
    fin >> N;

    for(int i = 1; i <= N; i++)
        fin >> V[i];

    if(N == 2) {
        fout << V[1] + V[2] << '\n';
        return 0;
    }

    for(int j = 1; j < 4; j++)
    {
        for(int i = N - 1; i > j; i--)
            DP[i] = max(DP[i + 1], max(DP[i + 2], V[i] + V[i + 1] + DP[i + 3]));

        ans = max(ans, DP[j + 1]);
        V[++N] = V[j], V[j] = 0;
    }

    fout << ans << '\n';

    fin.close();
    fout.close();

    return 0;
}