# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
946737 | hellowinchang1029 | Knapsack (NOI18_knapsack) | C++17 | 53 ms | 3544 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;
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vvi vector<vector<int>>
#define vt vector
#define arr array
#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
const int MOD1=998244353;
const int MOD2=1e9+7;
const ll LINF=1e18;
const int INF=1e9;
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll s, n;
cin>>s>>n;
map<ll, vt<pll>> items;
for (ll i=0; i<n; i++){
ll v, w, k;
cin>>v>>w>>k;
items[w].pb({v, k});
}
vt<pll> use_items;
for (ll i=1; i<=s; i++){
if (!items[i].size()) continue;
sort(rALL(items[i]));
for (ll j=0, id=0; j<=(s/i) && id<items[i].size(); j++){
use_items.pb({i, items[i][id].first});
if (!(--items[i][id].second)) id++;
}
}
vt<ll> dp(s+1, 0);
for (pll item : use_items){
for (ll j=s; j>=item.first; j--){
dp[j]=max(dp[j], dp[j-item.first]+item.second);
}
}
cout<<dp[s]<<'\n';
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... |