# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
828853 | raphaelp | Knapsack (NOI18_knapsack) | C++14 | 105 ms | 7960 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>
using namespace std;
int main()
{
int S, N;
cin >> S >> N;
vector<vector<int>> Tab(N, vector<int>(3));
for (int i = 0; i < N; i++)
{
cin >> Tab[i][0] >> Tab[i][1] >> Tab[i][2];
}
sort(Tab.begin(), Tab.end());
vector<vector<int>> Val(S + 1);
for (int i = N - 1; i >= 0; i--)
{
while (Tab[i][2] && Val[Tab[i][1]].size() * Tab[i][1] <= S)
{
Val[Tab[i][1]].push_back(Tab[i][0]);
Tab[i][2]--;
}
}
vector<int> dp(S + 1);
for (int i = 1; i <= S; i++)
{
for (int j = 0; j < Val[i].size(); j++)
{
for (int k = S - i; k >= 0; k--)
{
dp[k + i] = max(dp[k + i], dp[k] + Val[i][j]);
}
}
}
int ans = 0;
for (int i = 0; i <= S; i++)
{
ans = max(ans, dp[i]);
}
cout << ans;
}
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... |