# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
900586 | Servant_of_the_Lord | Knapsack (NOI18_knapsack) | C++17 | 50 ms | 5288 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
using namespace std;
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
ll x,y,z,a,b,c;
cin>>x>>y;
vector<ll>v(x+1);
vector<pair<ll,ll>>w;
vector<vector<pair<ll,ll>>>u(x+1);
for(ll i=0;i<y;i++)
{
cin>>a>>b>>c;
u[b].push_back({a,c});
}
for(ll i=1;i<=x;i++)
{
sort(u[i].begin(),u[i].end());
a=x/i;
while(u[i].size()&&a>0)
{
w.push_back({i,u[i].back().first});
u[i].back().second--;
a--;
if(!u[i].back().second)u[i].pop_back();
}
}
for(auto i:w)
{
for(ll j=x;j>=i.first;j--)
{
v[j]=max(v[j],v[j-i.first]+i.second);
}
}
cout<<v.back()<<'\n';
}
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... |