Cod sursa(job #2007239)

Utilizator SCatalinStanciu Catalin SCatalin Data 2 august 2017 12:36:45
Problema Oo Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <fstream>
using namespace std;

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

int v[100005],best[100005];

int main()
{
    int N,res=-1,i;
    in >> N;
    for (i = 1; i<=N; i++)
        in >> v[i];
    // iau 1 si 2
    best[2] = best[3] = best[4] = v[1]+v[2];
    for(i = 5; i <= N-1; i++)
    {
        best[i] = v[i]+v[i-1]+best[i-3];
        res = max(res, best[i]);
    }
    // nu iau 1 si 2
    best[0] = best[1] = best[2] = 0;
    for(i = 3; i <= N; i++)
    {
        best[i] = v[i]+v[i-1]+best[i-3];
        res = max(res, best[i]);
    }
    // iau 1 si N
    best[1] = best[2] = best[3] = v[1]+v[N];
    for(i = 4; i <= N-2; i++)
    {
        best[i] = v[i]+v[i-1]+best[i-3];
        res = max(res, best[i]);
    }
    out << res;
}