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;
using ll = long long;
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, s;
cin >> s >> n;
vector<ll> v(n), w(n), k(n);
for (int i = 0; i < n; i++) {
cin >> v[i] >> w[i] >> k[i];
}
vector<ll> dp(s + 1, 0);
auto add = [&](ll p, ll 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... |