Submission #1129878

#TimeUsernameProblemLanguageResultExecution timeMemory
1129878aloszaCandies (JOI18_candies)C++20
0 / 100
15 ms15936 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];
        }
    }
    cout << "\n";
    for(int k = 1; k < n2+1; k++)
    {
        for(int i = 2; i < n+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...