| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1358689 | Desh03 | Knapsack (NOI18_knapsack) | C++20 | 25 ms | 1852 KiB |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int s, n;
cin >> s >> n;
vector<vector<pair<int, int>>> br(s + 1);
for (int i = 0; i < n; i++) {
int r, v, k;
cin >> r >> v >> k;
br[v].push_back({r, k});
}
vector<pair<int, int>> cc;
for (int i = 1; i <= s; i++) {
sort(br[i].rbegin(), br[i].rend());
int k = s / i;
for (auto [x, y] : br[i]) {
for (int j = 0; j < min(k, y); j++) {
cc.push_back({i, x});
}
k -= min(k, y);
if (!k) break;
}
}
vector<long long> dp(s + 1);
for (auto [x, y] : cc) {
for (int j = s; j >= x; j--) {
dp[j] = max(dp[j], dp[j - x] + y);
}
}
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... | ||||
