// In the name of Allah
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<ld> cld;
#define all(x) (x).begin(),(x).end()
#define len(x) ((ll) (x).size())
#define F first
#define S second
#define pb push_back
#define sep ' '
#define endl '\n'
#define Mp make_pair
#define kill(x) cout << x << '\n', exit(0)
#define set_dec(x) cout << fixed << setprecision(x);
#define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = (2000 + 4);
const ll oo = 1e18 + 4;
int n; ll A[maxn];
ll dp[maxn][maxn]; int okx[maxn][maxn];
void solve() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> A[i];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= (n + 1) / 2; j++) dp[i][j] = -oo;
}
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= (i + 1) / 2; j++) {
dp[i][j] = dp[i - 1][j];
if (i == 1 && j - 1 >= 0) {
if (A[i] > dp[i][j]) {
dp[i][j] = A[i]; okx[i][j] = 1;
}
}
else if (i - 2 >= 0 && j - 1 >= 0) {
if (dp[i - 2][j - 1] + A[i] > dp[i][j]) {
dp[i][j] = dp[i - 2][j - 1] + A[i]; okx[i][j] = 1;
}
}
if (j - 1 >= 0 && okx[i][j] < okx[i][j - 1]) {
exit(23);
}
}
}
for (int j = 1; j <= (n + 1) / 2; j++) cout << dp[n][j] << endl;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int T = 1;
while (T--) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |