This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define sz(v) int(std::size(v))
using i64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<int> A(N);
for (auto &x : A) cin >> x;
int take = (N + 1) / 2;
vector dp(N, vector<i64>(take + 1, LLONG_MIN));
dp[0][0] = 0;
for (int i = 0; i < N; i++) {
if (i) dp[i] = dp[i - 1];
for (int j = 1; j <= take; j++)
dp[i][j] = max(dp[i][j], (i >= 2 ? dp[i - 2][j - 1] : j == 1 ? 0 : LLONG_MIN) + A[i]);
}
for (int j = 1; j <= take; j++) cout << dp[N - 1][j] << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |