#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n, i;
int podo[10000] = {0};
cin >> n;
for (i = 0; i < n; i++) {
cin >> podo[i];
}
int memo[10000][3] = {{0, 0, 0}};
memo[0][1] = podo[0];
for (i = 1; i < n; i++) {
memo[i][0] = *max_element(memo[i - 1], memo[i - 1] + 3);
memo[i][1] = memo[i - 1][0] + podo[i];
memo[i][2] = memo[i - 1][1] + podo[i];
}
cout << *max_element(memo[n - 1], memo[n - 1] + 3) << endl;
return 0;
}
문제의 조건(포도주를 연속 3잔 마실 수 없다)에 맞추어 3 * 10000 배열로 메모이제이션을 진행했다.
*max_element(memo[i - 1], memo[i - 1] + 3)
memo[i - 1][0] + podo[i]
memo[i - 1][1] + podo[i]