# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
907679 | Ca7Ac1 | Knapsack (NOI18_knapsack) | C++17 | 123 ms | 2640 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 <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <math.h>
#define ll int
#define pll pair<ll, ll>
using namespace std;
int main()
{
ll s;
ll n;
cin >> s >> n;
vector<priority_queue<ll, vector<ll>, greater<ll>>> arr(s, priority_queue<ll, vector<ll>, greater<ll>>());
for (ll i = 0; i < n; i++)
{
ll v;
ll w;
ll k;
cin >> v >> w >> k;
while (arr[w - 1].size() * w <= s && k > 0)
{
arr[w - 1].push(v);
k--;
}
while (arr[w - 1].top() < v && k > 0)
{
arr[w - 1].pop();
arr[w - 1].push(v);
k--;
}
}
vector<ll> dp(s + 1, 0);
for (ll i = 1; i <= s; i++)
{
auto &values = arr[i - 1];
while (!values.empty())
{
ll curr = values.top();
values.pop();
for (ll j = s; j >= 0; j--)
{
if (j + i <= s)
{
dp[j + i] = max(dp[j + i], dp[j] + curr);
}
}
}
}
ll sol = 0;
for (ll i : dp)
{
sol = max(sol, i);
}
cout << sol << '\n';
return 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... |