# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
45049 | RayaBurong25_1 | Candies (JOI18_candies) | C++17 | 34 ms | 16676 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 <stdio.h>
long long A[2005];
long long DP[2005][2005];
long long max(long long a, long long b)
{
return (a > b)?a:b;
}
int main()
{
//just a proof of concept
int N;
scanf("%d", &N);
int i, j;
for (i = 0; i < N; i++)
scanf("%lld", &A[i]);
for (i = 1; i <= (N + 1)/2; i++)
{
for (j = 2*(i - 1); j < N; j++)
{
if (i == 1) DP[j][i] = A[j];
if (j > 0) DP[j][i] = max(DP[j][i], DP[j - 1][i]);
if (j > 1) DP[j][i] = max(DP[j][i], DP[j - 2][i - 1] + A[j]);
// printf("%lld ", DP[j][i]);
}
// printf("\n");
printf("%lld\n", DP[N - 1][i]);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |