Cod sursa(job #2486432)

Utilizator Dorin07Cuibus Dorin Iosif Dorin07 Data 2 noiembrie 2019 21:04:18
Problema Oo Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.64 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];

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

}

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(){
    a[n+1] = a[1];
    int d1 = alg(1, n - 1);
    int d2 = alg(2, n);
    int d3 = alg(3, n + 1);
    fout << max(d1, max(d2, d3)) << "\n";
}

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