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_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int s, n;
std::cin >> s >> n;
std::map<int, std::vector<std::pair<int, int>>> m;
for (int i = 0; i < n; ++i) {
int v, w, k;
std::cin >> v >> w >> k;
m[w].push_back({v, k});
}
for (auto &[w, p] : m) {
std::sort(p.rbegin(), p.rend());
}
std::vector<std::vector<i64>> dp(m.size() + 1, std::vector<i64>(s + 1, 0));
int i = 0;
i64 ans = 0;
for (auto &[w, p] : m) {
i++;
for (int j = 0; j <= s; ++j) {
dp[i][j] = dp[i - 1][j];
int W = 0;
i64 V = 0;
for (auto [v, k] : p) {
if (W + w > j)
break;
int r = std::min((j - W) / w, k);
if (r <= 0)
break;
W += w * r;
V += 1ll * v * r;
dp[i][j] = std::max(dp[i][j], dp[i - 1][j - W] + V);
}
ans = std::max(ans, dp[i][j]);
}
}
std::cout << ans << "\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... |