제출 #1302532

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

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

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

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

    for (int i = 0; i < N; i++) {
        int v, w;
        long long k;
        cin >> v >> w >> k;

        for (long long p = 1; k > 0; p <<= 1) {
            long long take = min(p, k);
            k -= take;

            int W = take * w;
            long long V = take * v;

            for (int s = S; s >= W; s--) {
                dp[s] = max(dp[s], dp[s - W] + V);
            }
        }
    }

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