# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1069076 | vjudge1 | Knapsack (NOI18_knapsack) | C++17 | 0 ms | 0 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.
bool pro[s + 1] = {false};
pro[0] = true;
map<int, int> mp;
for(int x = 1; x < 2001; x++) mp[x] = s/x;
vector<pii> choose;
vector<iii> a;
for(int x = 0; x < n; x++)
{
int v, w, k; cin >> v >> w >> k;
a.push_back({v, w, k});
}
sort(a.begin(), a.end());
for(iii t : a)
{
int v = get<0>(t);
int w = get<1>(t);
int k = get<2>(t);
if(mp[w] >= k)
{
for(int x = 0; x < k; x++) choose.push_back({v, w});
mp[w] -= k;
}
else
{
for(int x = 0; x < mp[w]; x++) choose.push_back({v, w});
mp[w] = 0;
}
}
int mx = 0;
for(pii p : choose)
{
//cout << p.f << " " << p.s << "\n";
for(int x = s; x >= 0; x--)
{
if(x - p.s >= 0)
{
if(pro[x - p.s])
{
pro[x] = true;
dp[x] = max(dp[x], dp[x - p.s] + p.f);
mx = max(mx, dp[x]);
}
}
}
}
cout << mx;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
//freopen("wormsort.in", "r", stdin);
//freopen("wormsort.out", "w", stdout);
int t = 1;
//cin >> t;
while(t--)
{
solve();
}
return 0;
}