제출 #616010

#제출 시각아이디문제언어결과실행 시간메모리
616010bebraCandies (JOI18_candies)C++17
8 / 100
44 ms37212 KiB
#include <bits/stdc++.h>
using namespace std;

#define dbg(x) cerr << #x << ": " << x << endl;

const int MAX_N = (int)2000;
long long dp[MAX_N][MAX_N / 2];
const long long MINUS_INF = -1e15;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<long long> a(n);
    for (auto& x : a) cin >> x;
    for (int i = 0; i < MAX_N; ++i) {
        for (int j = 0; j < MAX_N / 2; ++j) {
            dp[i][j] = MINUS_INF;
        }
    }
    dp[0][0] = 0;
    dp[0][1] = a[0];
    for (int i = 1; i < n; ++i) {
        dp[i][0] = 0;
        for (int j = 1; j <= (i + 2) / 2; ++j) {
            dp[i][j] = max(dp[i - 1][j], a[i] + (i >= 2 ? dp[i - 2][j - 1] : 0));
        }
    }
    for (int j = 1; j <= (n + 1) / 2; ++j) {
        cout << dp[n - 1][j] << '\n';
    }
    return 0;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...