#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int S, N;
cin >> S >> N;
vector<int> V, W;
for (int i = 1; i <= N; i++) {
int v, w, k;
cin >> v >> w >> k; // đúng thứ tự theo đề
int pow = 1;
while (k >= pow) {
V.push_back(v * pow);
W.push_back(w * pow);
k -= pow;
pow <<= 1;
}
if (k > 0) {
V.push_back(v * k);
W.push_back(w * k);
}
}
vector<int> dp(S + 1, 0);
int n = V.size();
for (int i = 0; i < n; i++) {
for (int j = S; j >= W[i]; j--) {
dp[j] = max(dp[j], dp[j - W[i]] + V[i]);
}
}
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... |