Cod sursa(job #2936444)

Utilizator Dragono63Stanciu Rares Stefan Dragono63 Data 8 noiembrie 2022 20:40:57
Problema Oo Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.31 kb
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
using ll = long long;

using namespace std;

const int NMAX = 1e5 + 5;
/*******************************/
// INPUT / OUTPUT

ifstream f("oo.in");
ofstream g("oo.out");
/*******************************/
/// GLOBAL DECLARATIONS

int N;
int ans;
int v[NMAX], dp[NMAX];
/*******************************/
/// FUNCTIONS

void ReadInput();
void Solution();
void Output();
/*******************************/
///-------------------------------------
inline void ReadInput()
{
    f >> N;
    for (int i = 1 ; i <= N ; ++ i)
    {
        f >> v[i];
    }
    v[N + 1] = v[1];
}
///-------------------------------------
inline void get_max(int start)
{
    dp[start] = 0;
    dp[start + 1] = v[start] + v[start + 1];
    for (int i = start + 2 ; i <= N - 2 + start ; ++ i)
    {
        dp[i] = max(dp[i - 1], v[i] + v[i - 1] + dp[i - 3]);
    }
    ans = max(ans, dp[N - 2 + start]);
}
///-------------------------------------
inline void Solution()
{
    for (int i = 1 ; i <= 3 ; ++ i)
        get_max(i);
}
///-------------------------------------
inline void Output()
{
    g << ans;
}
///-------------------------------------
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ReadInput();
    Solution();
    Output();
    return 0;
}