# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
896752 | blackslex | Knapsack (NOI18_knapsack) | C++17 | 55 ms | 7536 KiB |
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 namespace std;
using ll = long long;
using pii = pair<ll, ll>;
const int M = 2005;
ll n, m, dp[M];
vector<pii> u[M], t;
int main() {
scanf("%lld %lld", &m, &n);
vector<ll> w(n), v(n), k(n);
for (int i = 0; i < n; i++) scanf("%lld %lld %lld", &v[i], &w[i], &k[i]), u[w[i]].emplace_back(v[i], k[i]);
for (int i = 1; i <= m; i++) {
ll cur = m / i;
sort(u[i].rbegin(), u[i].rend());
for (auto &[x, y]: u[i]) {
ll use = min(cur, y); cur -= use;
while (use--) t.emplace_back(x, i);
if (!use) break;
}
}
for (auto &[x, y]: t) for (int i = m; i >= y; i--) dp[i] = max(dp[i], dp[i - y] + x);
printf("%lld", dp[m]);
}
Compilation message (stderr)
# | 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... |