提交时间:2023-12-16 08:29:49
运行 ID: 116114
#include<iostream> using namespace std; const int N = 1e7; int f[N], a[N], n; int main(){ cin >> n; for(int i = 0; i < n; i++){ cin >> a[i]; } for(int i = 2; i < n; i++){ f[i] = max(f[i], f[i-2] + a[i-2]); if(i == 2) continue; f[i] = max(f[i], f[i-3] + a[i-3]); } cout << max(f[n-1] + a[n-1], f[n-2] + a[n-2]); return 0; }