# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
274218 | Halit | Candies (JOI18_candies) | C++17 | 102 ms | 32128 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;
int main(){
int n;
scanf("%d", &n);
vector<long long> v;
for(int i = 0;i < n;++i){
long long c;
scanf("%lld", &c);
v.push_back(c);
}
vector< vector<long long> > dp(n+5, vector<long long>(n+5,-1));
function<long long(int, int)> DP = [&](int i, int j) -> long long{
if(i >= n)
return (j > 0 ? -1e9 : 0);
if(dp[i][j] != -1)
return dp[i][j];
long long d = DP(i+1,j);
if(j > 0)
d = max(DP(i+2, j-1) + v[i], d);
return dp[i][j] = d;
};
for(int i = 1;i <= (n+1)/2;++i)
cout << DP(0,i) << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |