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(false); cin.tie(nullptr);
int S, n;
cin >> S >> n;
vector<ll> V, W;
for (int i = 0; i < n; i++) {
int v, w, k;
cin >> v >> w >> k;
k = min(k, S / w);
int x = 1;
while (x <= k) {
V.push_back((ll)v * x);
W.push_back((ll)w * x);
k -= x;
x <<= 1;
}
if (k) {
V.push_back((ll)v * k);
W.push_back((ll)w * k);
}
}
vector<ll> dp(S + 1, -1);
dp[0] = 0;
for (int i = 0; i < (int)V.size(); i++) {
for (int j = S; j >= W[i]; j--)
if (dp[j - W[i]] != -1) dp[j] = max(dp[j], dp[j - W[i]] + V[i]);
}
cout << *max_element(dp.begin(), dp.end());
}
# | 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... |