제출 #1275987

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

#define ll long long

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

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

    struct Item { ll v, w; };
    vector<Item> items;

    for (int i = 0; i < N; i++) {
        int V, W, K;
        cin >> V >> W >> K;
        // Binary split
        for (int p = 1; K > 0; p <<= 1) {
            int cnt = min(p, K);
            items.push_back({V * cnt, W * cnt});
            K -= cnt;
        }
    }

    vector<ll> dp(S + 1, 0);
    for (auto &it : items) {
        for (int j = S; j >= it.w; j--) {
            dp[j] = max(dp[j], dp[j - it.w] + it.v);
        }
    }

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