# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1064299 | vjudge1 | Knapsack (NOI18_knapsack) | C++17 | 29 ms | 10588 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>
#define int long long
#define endl '\n'
using namespace std;
const int maxn = 1e5 + 2;
int n,m;
int a[maxn];
int b[maxn];
int c[maxn];
int dp[maxn][2005];
int res[maxn];
main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// freopen("main.inp", "r", stdin);
// freopen("main.out", "w", stdout);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i] >> c[i];
}
for (int i = 1; i <= n; i++) {
dp[i][0] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
dp[i][j] = dp[i-1][j];
for (int k = 0; k <= min(c[i],j/a[i]); k++) {
if (dp[i-1][j-k*a[i]]+b[i]*k > dp[i][j]) {
//trace[i][j] = k;
dp[i][j] = dp[i-1][j-k*a[i]]+b[i]*k;
}
}
}
}
cout << dp[n][m];
}
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... |