# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
890567 | Flan312 | Knapsack (NOI18_knapsack) | C++17 | 3 ms | 600 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 ld long double
#define eb emplace_back
#define task ""
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define nx freopen (task".inp","r",stdin), freopen (task".out","w",stdout);
#define fi first
#define se second
#define pii pair <int, int>
#define tii tuple <int, int, int>
using namespace std;
const int nmax = 2002;
int s, n, v[nmax], w[nmax], k[nmax];
int mxk = 0;
void sub23()
{
vector <ll> dp(nmax, 0);
for (int i = 1; i <= n; ++i)
for (int j = s; j >= w[i]; --j)
for (int use = k[i]; use >= 0; --use)
if (j >= 1ll * w[i] * use)
dp[j] = max(dp[j], dp[j - w[i] * use] + 1ll * v[i] * use);
cout << dp[s];
exit(0);
}
int main()
{
if (ifstream(task".inp")) nx
fast
cin >> s >> n;
for (int i = 1; i <= n; ++i)
cin >> v[i] >> w[i] >> k[i],
mxk = max(mxk, k[i]);
if (n == 1) return cout << 1ll * v[1] * min(s / w[1], k[1]), 0;
if (n <= 100 && mxk <= 10) sub23();
}
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... |