제출 #1335295

#제출 시각아이디문제언어결과실행 시간메모리
1335295isaacsunKnapsack (NOI18_knapsack)C++20
73 / 100
1074 ms456 KiB
// Source: https://usaco.guide/general/io

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

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int maxWeight, numItems;
    cin >> maxWeight >> numItems;

    vector<int> dp(maxWeight + 1);

    for(int i = 0; i < numItems; i++) {
        int value, weight, copies;
        cin >> value >> weight >> copies;

        copies = min(copies, maxWeight / weight);

        int part = 1;
        while(copies > 0) {
            int size = min(part, copies);

            int w = weight * size;
            int v = value * size;
            
            for(int j = maxWeight; j - w >= 0; j--) {
                dp[j] = max(dp[j], dp[j - w] + v);
            }

            copies -= part;
            part <<= 1;
        }
    }

    cout << dp[maxWeight];
}
#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...