제출 #1301962

#제출 시각아이디문제언어결과실행 시간메모리
1301962vaderspaderKnapsack (NOI18_knapsack)C++20
73 / 100
1097 ms16160 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pii; typedef vector<ll> vi; typedef vector<vi> matrix; #define rep(i, a, b) for(ll i = a; i < b; i++) #define down(i, b, a) for(ll i = b - 1; i >= a; i--) int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); ll s, n; cin >> s >> n; vi v(0); vi w(0); rep(i, 0, n){ ll V, W, K; cin >> V >> W >> K; ll c = 1; while(K > c){ if(c * W <= s){ v.push_back(c * V); w.push_back(c * W); } K -= c; c <<= 1; } if(K * W <= s){ v.push_back(K * V); w.push_back(K * W); } } n = v.size(); vi dp(s + 1, 0); rep(i, 0, n){ down(j, s + 1, w[i]){ dp[j] = max(dp[j], dp[j - w[i]] + v[i]); } } ll best = 0; rep(i, 0, s + 1) best = max(best, dp[i]); cout << best << 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...