# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
486633 | my04 | Candies (JOI18_candies) | C++17 | 29 ms | 63052 KiB |
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>
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define S second
#define F first
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
void setIO(string name = "") {
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
if (sz(name)) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
const int inf = 1e9;
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int MAXN = 1e6 + 5;
int n;
ll a[2005];
ll dp[2005][2005][2];
void solve() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 0; i <= n + 1; i++) {
for (int j = 0; j <= n + 1; j++) {
for (int k = 0; k < 2; k++) {
dp[i][j][k] = -inf;
}
}
}
dp[1][1][1] = a[1];
dp[1][0][0] = 0;
for (int i = 2; i <= n; i++) {
for (int j = 0; j < i; j++) {
dp[i][j + 1][1] = max(dp[i][j + 1][1], dp[i - 1][j][0] + a[i]);
dp[i][j][0] = max(dp[i][j][0], max(dp[i - 1][j][0], dp[i - 1][j][1]));
}
}
for (int i = 1; i <= (n + 1) / 2; i++) {
cout << max(dp[n][i][1], dp[n][i][0]) << '\n';
}
}
main() {
//setIO();
int tt = 1;
// cin >> tt;
while (tt--) {
solve();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |