#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 105
#define maxw 10005
#define FOR(i , a , b) for(int i = a ; i <= b; i++)
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll dp[maxw] , A[maxn], w[maxn] , v[maxn];
int main(){
FAST;
int n;
ll W;
cin >> W >> n;
FOR(i , 1 , n) cin >> v[i] >> w[i] >> A[i];
FOR(i , 1 , n){
for(ll k = 1; A[i] > 0 ; k <<= 1){
ll cnt = min(k , A[i]);
A[i] -= cnt;
ll weight = w[i] * cnt;
ll cost = v[i] * cnt;
for(ll j = W ; j >= weight ; j--) dp[j] = max(dp[j] , dp[j - weight] + cost);
}
}
cout << dp[W];
}
# | 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... |