# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
598991 | Hanksburger | Knapsack (NOI18_knapsack) | C++17 | 61 ms | 3716 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;
vector<pair<int, int> > v[2005];
int dp[2005];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int s, n;
cin >> s >> n;
for (int i=1; i<=n; i++)
{
int a, b, c;
cin >> a >> b >> c;
v[b].push_back({a, c});
}
for (int i=1; i<=s; i++)
{
sort(v[i].rbegin(), v[i].rend());
int cnt=s/i;
for (int j=0; j<v[i].size(); j++)
{
while (cnt && (v[i][j].second--))
{
for (int k=s; k>=i; k--)
dp[k]=max(dp[k], dp[k-i]+v[i][j].first);
cnt--;
}
if (!cnt)
break;
}
}
cout << dp[s];
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... |