# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
984291 | duyanhloveav | Knapsack (NOI18_knapsack) | C++14 | 1073 ms | 1368 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;
const int mxn = 9 + 1e6;
const int inf = 0x3f3f3f3f;
const ll lnf = 0x3f3f3f3f3f3f3f3f;
void SaKaTa(void) {
int s, n;
cin >> s >> n;
vector<int> dp(s + 1), dp2 = dp;
for (int i = 0; i < n; ++i) {
int v, w, k;
cin >> v >> w >> k;
dp2 = dp;
for (int l = 1; l <= k; ++l) {
if (w * l > s) break;
for (int j = s; j >= w * l; --j) {
dp[j] = max(dp[j], dp2[j - w * l] + v * l);
}
}
}
cout << *max_element(begin(dp), end(dp));
}
int32_t main(void) {
#define task "SaKaTa"
cin.tie(0)->sync_with_stdio(0);
for (string iext : {"in", "inp"}) {
if (fopen((task "." + iext).c_str(), "r")) {
freopen((task "." + iext).c_str(), "r", stdin);
freopen(task ".out", "w", stdout);
}
}
int testcase = 1;
// cin >> testcase;
while (testcase--) SaKaTa();
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... |