# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
866334 | phuxtrohhg | Knapsack (NOI18_knapsack) | C++17 | 2 ms | 348 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 ll long long
#define pii pair<ll, ll>
#define st first
#define nd second
#define all(x) (x).begin(), (x).end()
#define mp(x) make_pair(x)
#define file "test"
using namespace std;
const double PI = 2 * acos(0);
const long long INF = 1e18;
const long long N = 2e6 + 5;
ll s, n, v[N], w[N], k[N];
ll dp[3000][3000];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen(file".inp","r",stdin); freopen(file".out","w",stdout);
#endif
cin >> s >> n;
for (int i = 1; i <=n; i++)
cin >> v[i] >> w[i] >> k[i];
// for (int i = 1; i <=n; i++)
// for (int j = 1; j <= s; j++)
// dp[i][j] = INF;
for (int i = 1; i <=n; i++)
for (int j = 1; j <= s; j++)
{
for (int sl = 1; w[i] * sl <= j && sl <= k[i]; sl++)
dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i] * sl] + v[i] * sl);
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
}
// for (int i = 1; i <=n; i++)
// {
// for (int j = 1; j <= s; j++)
// cout << dp[i][j] <<' ';
// cout << '\n';
// }
cout << dp[n][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... |