Submission #1308265

#TimeUsernameProblemLanguageResultExecution timeMemory
1308265ishat_jhaKnapsack (NOI18_knapsack)C++20
0 / 100
171 ms327680 KiB
/**
 *    author:  luminarae
 *    created: 05.01.2026 23:00:12
**/
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

#define int int64_t

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int nn, w;
    cin >> nn >> w;
    swap(nn, w);
    vector<pair<int, pair<int, int>>> vv(nn + 1);
    int n = 0;
    for(int i = 1; i <= nn; i++) {
        cin >> vv[i].first >> vv[i].second.first >> vv[i].second.second;
        n += vv[i].second.second;
    }
    vector<pair<int, int>> v;
    for(int i = 1; i <= nn; i++) {
        for(int j = 1; j <= vv[i].second.second; j++) {
            v.push_back(make_pair(vv[i].second.first, vv[i].first));
        }
    }
    vector<vector<int>> dp(n + 1, vector<int> (w + 1, 0LL));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j <= w; j++) {
            dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
            if(j + v[i].first <= w) {
                dp[i + 1][j + v[i].first] = max(dp[i + 1][j + v[i].first], dp[i][j] + v[i].second);
            }
        }
    }
    cout << *max_element(dp[n].begin(), dp[n].end()) << 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...