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>
int main(void) {
std::ios_base::sync_with_stdio(0);
std::cin.tie(nullptr);
int S, n; std::cin >> S >> n;
std::vector <std::vector <std::pair <int, int>>> items(S + 1);
for (int i = 0; i < n; i += 1) {
int v, w, k; std::cin >> v >> w >> k;
items[w].emplace_back(v, std::min(k, S / w));
}
std::vector <long long int> dp(S + 1);
for (auto& it : items) {
std::sort(it.begin(), it.end());
std::reverse(it.begin(), it.end());
}
for (int w = 1; w <= S; w += 1) {
for (const auto& [v, cnt] : items[w]) {
int total = 0;
for (int i = 1; i <= cnt and total <= S; i += 1) {
for (int t = S; t >= w; t -= 1)
dp[t] = std::max(dp[t], dp[t - w] + v);
total += w;
}
}
}
std::cout << dp.back() << '\n';
return 0^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... |