제출 #928283

#제출 시각아이디문제언어결과실행 시간메모리
928283CSQ31Knapsack (NOI18_knapsack)C++17
37 / 100
1 ms600 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; ll dp[2222]; int main() { int s,n; cin>>s>>n; vector<pair<ll,ll>>items; for(int i=0;i<n;i++){ ll v,w,k; cin>>v>>w>>k; for(int i=0;;i++){ ll p = (1<<i); if(k>=p){ k-=p; items.push_back({v*p,w*p}); } else break; } if(k)items.push_back({v*k,w*k}); } for(auto x : items){ int v = x.first; int w = x.second; for(int i = s;i >= w;i--)dp[i] = max(dp[i],dp[i - w] + v); } ll ans = 0; for(int i=0;i<=s;i++)ans = max(ans,dp[i]); cout<<ans<<'\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...