제출 #1330219

#제출 시각아이디문제언어결과실행 시간메모리
1330219quynhlam2012Knapsack (NOI18_knapsack)C++20
73 / 100
1095 ms436 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main(){
    FASTIO
    int S,N;
    cin>>S>>N;

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

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

        ll c=1;
        while(k>0){
            ll take=min(c,k);
            ll tw=w*take;
            ll tv=v*take;
            for(int j=S;j>=tw;j--){
                dp[j]=max(dp[j],dp[j-tw]+tv);
            }
            k-=take;
            c<<=1;
        }
    }

    cout<<dp[S];
    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...