# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
785615 | 0x34c | Knapsack (NOI18_knapsack) | C++17 | 104 ms | 3668 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<int, int>
using namespace std;
int main()
{
int S, N;
cin >> S >> N;
vector<vector<pii>> wei(S + 1);
for (int i = 0; i < N; i++)
{
int v, w, k;
cin >> v >> w >> k;
wei[w].push_back({v, k});
}
for (int i = 1; i <= S; i++)
sort(wei[i].begin(), wei[i].end(), greater<pii>());
vector<ll> dp(S + 1, 0);
ll ans = 0;
for (int i = 1; i <= S; i++)
{
int idx = 0;
for (int j = 0; j < S / i && idx < wei[i].size(); j++)
{
for (int k = S; k >= i; k--)
{
dp[k] = max(dp[k], dp[k - i] + wei[i][idx].first);
ans = max(ans, dp[k]);
}
wei[i][idx].second--;
if (wei[i][idx].second == 0)
idx++;
}
}
cout << ans << endl;
}
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... |