# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
636354 | TUNGDUONGWILLWINVOI2023 | Knapsack (NOI18_knapsack) | C++14 | 64 ms | 3616 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 <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
const int NAXM = 2e3 + 5;
int S, N, dp[NAXM];
vector<vector<array<int, 2>>> a;
int main() {
// Coding
scanf("%d%d", &S, &N);
a.resize(S + 1);
for (int i = 0; i < N; ++i) {
int v, w, k;
scanf("%d%d%d", &v, &w, &k);
a[w].push_back({v, k});
}
for (int i = 1; i <= S; ++i) {
sort(a[i].begin(), a[i].end(),
[&](const array<int, 2> &x, const array<int, 2> &y) {
return x[0] > y[0];
});
}
for (int i = 1; i <= S; ++i) {
int id = 0;
for (int j = 0; j < S / i; ++j) {
if (id >= int(a[i].size())) {
break;
}
for (int t = S - i; t >= 0; --t) {
dp[t + i] = max(dp[t + i], dp[t] + a[i][id][0]);
}
--a[i][id][1];
if (!a[i][id][1]) {
++id;
}
}
}
int ans = 0;
for (int i = 0; i <= S; ++i) {
ans = max(ans, dp[i]);
}
printf("%d\n", ans);
return 0;
}
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... |