제출 #1332795

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int W,n;
    cin >> W >> n;

    vector<ll>dp(W+1,0);
    
    for (int i=0; i<n; i++) {
        ll v,w,k;
        cin >> v >> w >> k;
        
        int c = 1;
        
        while (k >= c) {
            for (int j = W; j>=c*w; j--) dp[j] = max(dp[j],dp[j-c*w]+c*v);
            k-=c;
            c <<= 1;
        }

        if (k) for (int j = W; j>=k*w; j--) dp[j] = max(dp[j],dp[j-k*w]+k*v);
    }

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