# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1047885 | manhlinh1501 | Knapsack (NOI18_knapsack) | C++17 | 4 ms | 3416 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 i64 = long long;
const int MAXN = 1e5 + 5;
struct PRODUCT {
int c, w, x;
PRODUCT(int c = 0, int w = 0, int x = 0) : c(c), w(w), x(x) {}
};
int N, S;
PRODUCT a[MAXN];
namespace subtask {
const int MAXN = 105;
const int MAXV = 2e3 + 5;
i64 dp[MAXN][MAXV];
void solution() {
for(int i = 1; i <= N; i++) {
auto [c, w, x] = a[i];
for(int j = 0; j <= S; j++) dp[i][j] = dp[i - 1][j];
for(int z = 0; z <= x; z++) {
for(int j = S; j >= w * x; j--)
dp[i][j] = max(dp[i][j], dp[i - 1][j - w * z] + 1LL * c * z);
}
}
i64 ans = 0;
for(int i = 1; i <= S; i++)
ans = max(ans, dp[N][i]);
cout << ans;
}
}
signed main() {
#define TASK "code"
if (fopen(TASK ".inp", "r")) {
freopen(TASK ".inp", "r", stdin);
freopen(TASK ".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> S >> N;
for(int i = 1; i <= N; i++) cin >> a[i].c >> a[i].w >> a[i].x;
subtask::solution();
return (0 ^ 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... |