Submission #1129895

#TimeUsernameProblemLanguageResultExecution timeMemory
1129895aloszaCandies (JOI18_candies)C++20
8 / 100
444 ms589824 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int n2 = (n+1)/2; vector<int> candies(n); for(int i = 0; i < n; i++) { cin >> candies[i]; } vector<vector<ll>> dp(n2+1); //k, index for(int k = 0; k < n2+1; k++) { dp[k] = vector<ll>(n+1); if(k > 0) { dp[k][1] = candies[0]; } } for(int k = 1; k < n2+1; k++) { for(int i = 2; i < n+1; i++) { if(2*(k-1) < i) dp[k][i] = max(dp[k][i-1], dp[k-1][i-2] + candies[i-1]); } cout << dp[k][n] << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...