Cod sursa(job #2486428)

Utilizator Dorin07Cuibus Dorin Iosif Dorin07 Data 2 noiembrie 2019 20:55:12
Problema Oo Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <bits/stdc++.h>
#define N 100005
using namespace std;

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

int n, a[N], b[N], maxi = -1;

void citire(){
    fin>>n;
    for(int i = 1; i <= n; ++i)
        fin>>a[i];
    a[n+1] = a[1];
}

int alg(int s, int f){

    b[s] = 0;
    b[s+1] = a[s] + a[s+1];
    for(int i = s + 2; i <= f; ++i)
        b[i] = max((a[i] + a[i-1] + b[i-3]), b[i-1]);
    return b[f];
}

void hehe(){
    int k, maxi = -1;
    for(int i = 1; i <= 3; ++i){
        int d = n-1;
        k = alg(i, d);
        ++d;
        if(k > maxi)
            maxi = k;
    }
    fout<<maxi;
}

int main(){
    citire();
    hehe();
    fin.close();
    fout.close();
}