#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
cin.tie(NULL)->ios_base::sync_with_stdio(false);
int s, n; cin >> s >> n;
vector<vector<ll>> dp(n+1, vector<ll>(s+1, 0LL));
for(int i=1; i<=n; i++){
ll v, w, k; cin >> v >> w >> k;
// value, weight, copies
for(int j=s; j>=w; j--){
for(int d=w; d<=min(ll(j), k*w); d+=w){
// d is cost of some k_i copies of an item
dp[i][j] = max(max(dp[i][j], dp[i-1][j]), dp[i-1][j-d] + v * d / w);
}
}
}
//for(auto i : dp){for(auto j : i) cout << j << ' '; cout << '\n';}
cout << dp[n][s];
return 0;
}
/*
15 3
1000000000 5 1000000000
100 3 100
1 5 2
*/
# | 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... |