#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
constexpr ll MAXN=3e5+5,MAXV=3e5,MOD=1e9+7,INF=1e18;
ll n,m,i,j,p,k,ans,dem,st,en,dp[MAXN];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>m>>n;
for(i=1;i<=n;i++){
ll weight,cost,cnt;
cin>>cost>>weight>>cnt;
for(j=m;j>=weight;j--){
for(ll k=1;k<=cnt&&j-k*weight>=0;k++){
dp[j]=max(dp[j],dp[j-k*weight]+cost*k);
}
}
}
cout<<*max_element(dp+1,dp+m+1);
}
# | 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... |