Submission #47825

#TimeUsernameProblemLanguageResultExecution timeMemory
47825InovakCandies (JOI18_candies)C++14
8 / 100
268 ms64524 KiB
#include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define mk make_pair #define ll long long #define OK puts("OK") #define sz(s) (int)s.size() #define all(s) s.begin(), s.end() using namespace std; const int N = 2010; const ll inf = 1e15+7; int n, a[N]; ll dp[N][N]; int main() { cin >> n; for(int i = 0; i <= n; i++) for(int j = 0; j <= n; j++) dp[i][j] = -inf; dp[0][0] = 0; for(int i = 1; i <= n; i++) { cin >> a[i]; if(i == 1) { dp[1][0] = 0, dp[1][1] = a[1]; } else { for(int j = 0; j <= n; j++) { dp[i][j] = dp[i - 1][j]; if(j > 0) dp[i][j] = max(dp[i][j], dp[i - 2][j - 1] + a[i]); } } } for(int i = 1; i <= (n + 1) / 2; i++) cout << dp[n][i] << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...