제출 #1333466

#제출 시각아이디문제언어결과실행 시간메모리
1333466isaacsunKnapsack (NOI18_knapsack)C++20
73 / 100
1095 ms440 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, items;
    cin >> maxWeight >> items;

    vector<int> dp(maxWeight + 1);

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

        for(int i = maxWeight; i >= weight; i--) {
            int maxValue = 0;
            for(int j = 0; j <= quantity; j++) {
                if(i - weight * j < 0) {
                    break;
                }
                maxValue = max(maxValue, dp[i - weight * j] + value * j);
            }
            dp[i] = maxValue;
        }
    }

    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...