#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MX = 100005;
int S, n;
int v[MX], w[MX], k[MX];
int f[2005];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> S >> n;
for(int i=1; i<=n; i++) cin >> v[i] >> w[i] >> k[i];
for(int i=1; i<=n; i++){
k[i] = min(k[i], S/w[i]);
for(int t=1; k[i]>0; t=min(k[i], t<<1)){
int val = v[i]*t;
int wei = w[i]*t;
for(int j=S; j>=wei; j--){
f[j] = max(f[j], f[j-wei] + val);
}
k[i] -= t;
}
}
cout << *max_element(f + 0, f + S + 1);
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... |