# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
50147 | spencercompton | Candies (JOI18_candies) | C++17 | 180 ms | 35328 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;
long long ar[200000];
int n;
long long dp[2000][1001];
long long inf = 200000000000000003LL;
long long go(int now, int rem){
if(rem==0){
return 0LL;
}
if(now>=n){
return -inf;
}
if(dp[now][rem]>=-inf){
return dp[now][rem];
}
long long ret = -inf;
ret = max(ret,go(now+1,rem));
ret = max(ret,go(now+2,rem-1)+ar[now]);
dp[now][rem] = ret;
return ret;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i = 0; i<n; i++){
cin >> ar[i];
}
for(int a = 0; a<n; a++){
for(int b = 0; b<=(n+1)/2; b++){
dp[a][b] = -inf-2LL;
}
}
vector<long long> ans;
for(int i = 1; i<=(n+1)/2; i++){
ans.push_back(go(0,i));
}
for(int i = 2; i<ans.size(); i++){
assert((ans[i]-ans[i-1])<=(ans[i-1]-ans[i-2]));
}
for(int i = 0; i<ans.size(); i++){
cout << ans[i] << "\n";
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |