Cod sursa(job #1375191)

Utilizator gedicaAlpaca Gedit gedica Data 5 martie 2015 12:31:55
Problema Oo Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <fstream>
#include <algorithm>

using namespace std;

const int NMAX= 100000;

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

int v[NMAX+1], d[NMAX+1];

int main(  )
{
    int N, ans= 0, aux= 0;
    in >> N;

    for( int i= 1; i<=N; ++i )
    {
        in >> v[i];
    }

    v[N+1] = v[1];

    for( int i= 1; i<=4; ++i )
    {
        aux= N - 2 + i;
        d[i]= 0;
        d[i+1] = v[i] + v[i+1];

        for( int j= i+2; j<=aux; ++j )
        {
            d[j]= max( d[j-1], d[j-3] + v[j] + v[j-1] );
        }

        if( ans < d[aux] )
        {
            ans= d[aux];
        }

    }

    out << ans << '\n';

    return 0;
}