#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, S;
cin >> N >> S;
vector<int> dp(S + 1, 0);
for (int i = 0; i < N; ++i) {
int V, W, K;
cin >> V >> W >> K;
// Giới hạn số lượng theo sức chứa
long long max_take = min<long long>(K, S / W);
// Tách nhị phân
for (int t = 1; max_take > 0; t <<= 1) {
int num = min<long long>(t, max_take);
int weight = num * W;
int value = num * V;
for (int s = S; s >= weight; --s) {
dp[s] = max(dp[s], dp[s - weight] + value);
}
max_take -= num;
}
}
cout << dp[S] << "\n";
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |