# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
866376 | phuxtrohhg | Knapsack (NOI18_knapsack) | C++14 | 43 ms | 4908 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;
ll dp[N];
vector<pii> w[3005];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> s >> n;
for (ll i = 1; i <=n; i++)
{
ll v, wai, k;
cin >> v >> wai >> k;
w[wai].push_back({v, k});
}
for (ll i = 1; i <= s; i++)
{
if (!w[i].size()) continue;
sort(all(w[i]), greater<pii>());
ll curw = i;
for (ll r = 0; r < w[i].size(); r++)
{
if (curw > s) break;
for (ll sl = 1; sl <= w[i][r].nd && curw <= s; sl++, curw += i)
for (ll j = s; j >= i * sl; j--)
dp[j] = max(dp[j], dp[j - i] + w[i][r].st);
}
}
cout << dp[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... |