제출 #1330003

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

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

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

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

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

        for(long long power = 1; Ki > 0; power <<= 1) {
            long long take = min(power, Ki);
            long long weight = take * Wi;
            long long 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...