Submission #1209797

#TimeUsernameProblemLanguageResultExecution timeMemory
1209797borekkingKnapsack (NOI18_knapsack)C++20
12 / 100
1 ms1608 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int s, n; cin >> s >> n;
    vector<int> weight(1), profit(1);
    for (int i = 0; i < n; i++) {
        int v, w, k; cin >> v >> w >> k;
        int amount = min(s/w + 1, k);
        for (int j = 0; j < amount; j++) {
            weight.push_back(w);
            profit.push_back(v);
        }
    }
    n = weight.size();
    vector<vector<ll>> dp(s+1, vector<ll>(n, 0));
    for (int w = 1; w <= s; w++) {
        for (int i = 1; i < n; i++) {
            dp[w][i] = dp[w-1][i];
            if (w-weight[i] >= 0) {
                dp[w][i] = max(dp[w][i], profit[i] + dp[w-weight[i]][i-1]);
            }
        }
    }
    cout << dp[s][n-1] << endl;
    return 0;
}
#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...