Pagini recente » Cod sursa (job #18646) | Cod sursa (job #2230860) | Cod sursa (job #2696751) | Cod sursa (job #1650924) | Cod sursa (job #2936444)
#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;
}