#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int64_t> a(n + 1);
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<vector<int64_t>> dp(n + 1, vector<int64_t>(n + 1));
dp[1][1] = a[1];
for(int i = 2; i <= n; i++) {
for(int j = 1; j <= (i + 1) / 2; j++) {
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
dp[i][j] = max(dp[i][j], dp[i - 2][j - 1] + a[i]);
}
}
for(int i = 1; i <= (n + 1) / 2; i++) {
cout << dp[n][i] << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |