제출 #1304975

#제출 시각아이디문제언어결과실행 시간메모리
13049752120minhdtKnapsack (NOI18_knapsack)C++20
73 / 100
1095 ms584 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int S, N; if (!(cin >> S >> N)) return 0; vector<ll> dp(S + 1, 0); for (int i = 0; i < N; ++i) { ll v, w, k; cin >> v >> w >> k; k = min(k, (ll)S / w); for (ll m = 1; k > 0; m <<= 1) { ll num = min(m, k); ll total_v = num * v; ll total_w = num * w; for (int j = S; j >= total_w; --j) { dp[j] = max(dp[j], dp[j - (int)total_w] + total_v); } k -= num; } } ll result = 0; for (int j = 0; j <= S; ++j) { result = max(result, dp[j]); } cout << result << endl; 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...