Submission #970717

#TimeUsernameProblemLanguageResultExecution timeMemory
97071754skyxenonKnapsack (NOI18_knapsack)C++17
0 / 100
1 ms604 KiB
// https://oj.uz/problem/view/NOI18_knapsack

#include <bits/stdc++.h>
using namespace std;

#define int long long

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    assert(false);

    int s, n;
    cin >> s >> n;

    vector<tuple<int, int, int>> items;
    for (int i = 0; i < n; i++) {
        int v, w, k;
        cin >> v >> w >> k;
        items.push_back({v, w, k});
    }

    vector<vector<int>> dp(n + 1, vector<int>(s + 1, 0));

    for (int i = 1; i <= n; i++) {
        auto [v, w, k] = items[i - 1];
        for (int j = 1; j <= s; j++) {
            for (int repeat = 1; repeat <= k && (repeat * w <= j); repeat++) {
                dp[i][j] = max(dp[i][j], v * repeat + dp[i - 1][j - repeat * w]);
            }
        }
    }

    cout << dp[n][s] << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...