Submission #1263720

#TimeUsernameProblemLanguageResultExecution timeMemory
1263720NHristovCandies (JOI18_candies)C++20
0 / 100
6 ms12352 KiB
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

const int N=2e3+5;

int n;
int a[N], dp[N][N];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    for(int i=1; i<=n; i++) {
        cin >> a[i];
    }
    dp[1][1]=a[1], dp[2][1]=max(a[1], a[2]);
    for(int i=3; i<=n; i++) {
        for(int q=1; q<=(i+1)/2; q++) {
            dp[i][q]=max(dp[i-1][q], max(dp[i-2][q-1], dp[i-3][q-1])+a[i]);
        }
    }
    for(int i=1; i<=(n+1)/2; i++) cout << dp[n][i] << endl;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...