# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
826405 | NoLove | Knapsack (NOI18_knapsack) | C++14 | 1081 ms | 3924 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.
/**
* author : Lăng Trọng Đạt
* created: 2023-08-15
**/
#include <bits/stdc++.h>
using namespace std;
#ifndef LANG_DAT
#define db(...) ;
#endif // LANG_DAT
#define int int64_t
using pii = pair<int, int>;
const int MAXN = 1e5 + 5;
int w[MAXN], v[MAXN], k[MAXN];
int n, s;
int dp[MAXN];
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
if (fopen("hi.inp", "r")) {
freopen("hi.inp", "r", stdin);
// freopen("hi.out", "w", stdout);
}
cin >> s >> n;
for (int i = 0; i < n; i++) {
cin >> v[i] >> w[i] >> k[i];
}
for (int i = 0; i < n; i++) {
for (int x = 0; x < min(k[i], s); x++) {
for (int j = s; j >= w[i]; j--) {
if (j >= w[i]) {
dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
}
}
}
}
cout << dp[s];
}
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... |