제출 #1330002

#제출 시각아이디문제언어결과실행 시간메모리
1330002pucam20102Knapsack (NOI18_knapsack)C++20
0 / 100
1 ms344 KiB
#include <bits/stdc++.h>
using namespace std;

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

    int N, S;
    cin >> N >> S;

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

    for(int i = 0; i < N; i++) {
        int Vi, Wi, Ki;
        cin >> Vi >> Wi >> Ki;

        for(int power = 1; Ki > 0; power <<= 1) {
            int take = min(power, Ki);
            int weight = take * Wi;
            int value  = take * Vi;

            for(int j = S; j >= weight; j--) {
                dp[j] = max(dp[j], dp[j - weight] + value);
            }

            Ki -= take;
        }
    }

    cout << dp[S] << "\n";
    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...