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});
}
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++;
std::sort(p.rbegin(), p.rend());
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 > j)
break;
for (int l = 0; l < k; ++l) {
W += w;
V += v;
if (W > j)
break;
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... |