# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
698887 | Caubethieunang | Knapsack (NOI18_knapsack) | C++14 | 59 ms | 4960 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.
/// (*^_^*) Author : Cau_be_thieu_nang
#include <bits/stdc++.h>
#define ll long long
#define LOG 20
#define MASK(i) (1LL<<(i))
#define BIT(x,i) (((x)>>(i))&1)
#define FIRST_BIT(mask) __builtin_ctz((mask)&(-mask))
#define ERASE_BIT(mask) (mask)^((mask)&(-mask))
#define left _left
#define right _right
#define task "t"
using namespace std;
const ll INF=1e18;
const int iat=1e6+9;
const int mod=1e9+7;
void fast_IO()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
if(fopen(task".inp","r"))
{
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
}
int s,n;
vector <pair<ll,ll>> store[2001];
ll dp[2001];
signed main()
{
fast_IO();
cin>>s>>n;
for(int i=1; i<=n; i++)
{
int v,w,k;
cin>>v>>w>>k;
store[w].push_back({v,k});
}
for(int weight=0; weight<=s; weight++)
{
if(store[weight].empty())continue;
sort(store[weight].begin(),store[weight].end(),greater<pair<ll,ll>>());
int pos=0;
for(int i=0; weight*i<s; i++)
{
if(pos>=store[weight].size())break;
for(int lim=s; lim>=weight; lim--)dp[lim]=max(dp[lim],dp[lim-weight]+store[weight][pos].first);
store[weight][pos].second--;
if(!store[weight][pos].second)pos++;
}
}
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... |