#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pb push_back
#define mpr make_pair
const ll N=2e5 + 10 , mod=1e9 + 7;
const double eps=1e-6;
using namespace std;
ll n,m,a,b,c,s,q,x,k;
ll t[N];
string ch;
vector<vector<ll>>v;
ll res=0;
int main(){
ios_base::sync_with_stdio (0); cin.tie(0),cout.tie(0);
// freopen("time.in","r",stdin);
// freopen("time.out","w",stdout);
ll T=1;
//cin>>T;
while(T--){
cin>>s>>n;
vector<ll>v,w,c;
for(ll i=0;i<n;i++){
ll x,y,z;
cin>>x>>y>>z;
for(ll j=0;j<z;j++){
v.pb(x);
w.pb(y);
}
}
n=v.size();
ll dp[n+5][s+5];
memset(dp,0,sizeof(dp));
for(ll i=1;i<=n;i++){
for(ll j=0;j<=s;j++){
dp[i][j]=dp[i-1][j];
if(j>=w[i-1])
dp[i][j]=max(dp[i][j],dp[i-1][j-w[i-1]]+v[i-1]);
}
}
cout<<dp[n][s]<<"\n";;
}
return 0;
}
/*
1
41
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... |