#include<bits/stdc++.h>
#define ll int
#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;
ll v[n+5],w[n+5],c[n+5];
vector<ll>t;
for(ll i=0;i<n;i++){
cin>>v[i]>>w[i]>>c[i];
}
ll dp[n*s+5][s+2];
memset(dp,0,sizeof(dp));
dp[0][0]=0;
ll res=0;
ll x=1;
for(ll i=1;i<=n;i++){
for(ll j=0;j<min(s,c[i-1]);j++){
for(ll k=0;k<=s;k++){
dp[x][k]=dp[x-1][k];
if(k>=w[i-1]){
dp[x][k]=max(dp[x][k],dp[x-1][k-w[i-1]]+v[i-1]);
}
}
x++;
//cout<<i<<" "<<j<<" "<<dp[i+j][k]<<" \n";
res=max(res,dp[x-1][s]);
}
}
cout<<res<<"\n";
}
return 0;
}
/*
20 3
5000 15 1
100 1 3
50 2 4
*/
# | 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... |