제출 #1331398

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

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

    long long s, n;
    cin >> s >> n;

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

    for(int i = 0; i < n; i++) {
        long long v1, w1, k1;
        cin >> v1 >> w1 >> k1;

        long long cnt = k1;   // important fix

        for(long long j = 1; j <= cnt; j <<= 1) {
            long long take = min(j, cnt);

            long long new_v = v1 * take;
            long long new_w = w1 * take;

            for(long long curr = s; curr >= new_w; curr--) {
                dp[curr] = max(dp[curr], new_v + dp[curr - new_w]);
            }

            cnt -= take;
        }
    }

    cout << dp[s] << endl;
}
#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...