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 m, n;
std::cin >> m >> n;
std::vector item(1 + m, std::vector<std::tuple<int, int>>());
for (int i = 0; i < n; i++) {
int v, w, k;
std::cin >> v >> w >> k;
item[w].push_back({v, k});
}
std::vector<int> dp(1 + m);
for (int w = 1; w <= m; w++) {
std::sort(item[w].begin(), item[w].end(), std::greater<std::tuple<int, int>>());
for (int j = m; j >= 0; j--) {
[&]() {
int val = 0, wt = 0;
for (auto [v, k] : item[w]) {
for (int c = 0; c < k; c++) {
val += v, wt += w;
if (j + wt > m) {
return;
}
dp[j + wt] = std::max(dp[j + wt], dp[j] + val);
}
}
}();
}
}
std::cout << dp[m] << "\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... |