#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(nullptr);
#define ll long long
int main() {
fast;
ll w,n;
cin>>w>>n;
vector<priority_queue<pair<ll,ll>>>b(w+1);
for(ll i=0;i<n;i++){
ll vl,q,wt;
cin>>vl>>wt>>q;
b[wt].push({vl,q});
}
vector<ll>dp(w+1,0);
for(ll i=1;i<=w;i++){
ll ft=w/i;
while(!b[i].empty() && ft>0){
auto[vl,q]=b[i].top();
b[i].pop();
if(q>ft) q=ft;
ft-=q;
for(ll j=0;j<q;j++){
for(ll k=w;k>=i;k--){
dp[k]=max(dp[k],dp[k-i]+vl);
}
}
}
}
cout<<*max_element(dp.begin(),dp.end())<<'\n';
}
# | 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... |