# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1130674 | CrabCNH | Candies (JOI18_candies) | C++20 | 11 ms | 16192 KiB |
#include <bits/stdc++.h>
#define task "BriantheCrab"
#define int long long
#define pii pair <int, int>
#define fi first
#define se second
#define szf sizeof
#define sz(s) (int)((s).size())
using namespace std;
template <class T> void mini (T &t, T f) {if (t > f) t = f;}
template <class T> void maxi (T &t, T f) {if (t < f) t = f;}
const int maxN = 1e5 + 5;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
int n;
int a[maxN];
namespace sub1 {
int dp[2005][2005]; // max val at the i-th place and choose j
void sol () {
for (int i = 1; i <= n; i ++) {
for (int j = 0; j <= (i + 1) / 2; j ++) {
if (j == 0) {
dp[i][j] = max (dp[i - 1][j], 0LL);
}
else {
if (i >= 1) {
dp[i][j] = max (dp[i - 1][j], dp[i - 2][j - 1] + a[i]);
}
else {
dp[i][j] = dp[i - 1][j];
}
}
}
}
for (int i = 1; i <= (n + 1) / 2; i ++) {
cout << dp[n][i] << '\n';
}
}
}
void Solve () {
cin >> n;
for (int i = 1; i <= n; i ++) {
cin >> a[i];
}
sub1 :: sol ();
}
signed main () {
cin.tie (nullptr) -> sync_with_stdio (false);
if (fopen (task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
int t = 1;
//cin >> t;
while (t --) {
Solve ();
}
return 0;
}
// Belligerent :)
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |