# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
772134 | Oscar123123 | Knapsack (NOI18_knapsack) | C++17 | 1081 ms | 556 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;
int dp[2001]; bool vis[2001];
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
vis[0] = true;
int S, N; cin >> S >> N;
int ans = 0;
for (int i = 0; i < N; ++i) {
int v, w, k;
cin >> v >> w >> k;
for (int i = 2000; i >= 0; --i) {
if (vis[i] >= 0) {
for (int c = 1; c <= min((int)floor((S - i) / w), k); ++c) {
dp[c * w + i] = max(dp[c * w + i], dp[i] + c * v);
ans = max(ans, dp[c * w + i]);
vis[c * w + i] = true;
}
}
}
}
cout << ans << '\n';
}
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... |