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 i64 = long long;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int S, N;
std::cin >> S >> N;
std::vector<int> dp(1 + S);
for (int i = 0; i < N; i++) {
int v, w, k;
std::cin >> v >> w >> k;
for (int c = 1; c <= k; c *= 2) {
for (int j = S - w * c; j >= 0; j--) {
dp[j + w * c] = std::max(dp[j + w * c], dp[j] + v * c);
}
k -= c;
}
if (k) {
for (int j = S - w * k; j >= 0; j--) {
dp[j + w * k] = std::max(dp[j + w * k], dp[j] + v * k);
}
}
}
std::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... |