#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<ll,ll>
#define sz size()
#define all(v) v.begin(),v.end()
#define fi first
#define se second
const int N = 3e5;
const int mod = 1e9+7;
const ll INF = 1e18;
const int di[] = {1, -1, 0, 0};
const int dj[] = {0, 0, 1, -1};
void solve() {
int n,s;
cin>>s>>n;
ll v[n+1],w[n+1],k[n+1];
for(int i = 1; i <= n; i++){
cin>>v[i]>>w[i]>>k[i];
}
ll dp[s+1];
memset(dp,0,sizeof(dp));
for(int i = 1; i <= n; i++){
for(int K = 1; K <= k[i] && K*w[i]<=s; K++){
for(int j = s; j >= w[i]; j--){
dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
}
}
}
ll ans=0;
for(int i = 1; i <= s; i++){
ans=max(ans,dp[i]);
}
cout<<ans<<"\n";
}
int main() {
//freopen("cowrun.in","r",stdin);
//freopen("cowrun.out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t=1;
//cin>>t;
while(t--) {
solve();
}
return 0;
}
# | 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... |