# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1037083 | LucaDantas | Candies (JOI18_candies) | C++17 | 6 ms | 31608 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>
using namespace std;
constexpr int maxn = 2010, maxk = 2010;
int a[maxn];
long long dp[maxn][maxk];
int main() {
int n; scanf("%d", &n);
for(int i = 1; i <= n; i++)
scanf("%d", a+i);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= (i+1)/2; j++)
dp[i][j] = max({dp[i-1][j], (i >= 2 ? dp[i-2][j-1] : 0) + a[i]});
for(int j = 1; j <= (n+1)/2; j++)
printf("%lld\n", dp[n][j]);
// puts("VALORES");
// for(int i = 1; i <= n; i++) {
// for(int j = 1; j <= (i+1)/2; j++)
// printf("%d ", dp[i][j]);
// printf("\n");
// }
// puts("DELTAS");
// for(int i = 1; i <= n; i++) {
// printf("(%d) ", a[i]);
// for(int j = 1; j <= (i+1)/2; j++)
// printf("%d ", dp[i][j] - dp[i][j-1]);
// printf("\n");
// }
// for(int i = 1; i <= n; i++)
// for(int j = 2; j <= (i+1)/2; j++)
// assert(dp[i][j] - dp[i][j-1] <= dp[i][j-1] - dp[i][j-2]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |