This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, s;
cin >> s >> n;
vector<int> v(n), w(n), k(n);
for (int i = 0; i < n; i++) {
cin >> v[i] >> w[i] >> k[i];
}
vector<int> dp(s + 1, 0);
auto add = [&](int p, int c) {
for (int i = s; i >= c; i--) {
dp[i] = max(dp[i], dp[i - c] + p);
}
};
for (int i = 0; i < n; i++) {
for (int j = 0; j < 30; j++) {
if (1 << j <= k[i]) {
add(v[i] << j, w[i] << j);
k[i] -= 1 << j;
}
}
if (k[i] > 0) add(v[i] * k[i], w[i] * k[i]);
}
cout << dp[s] << '\n';
return 0;
}
# | 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... |