#include <bits/stdc++.h>
using namespace std;
#define inf 1e15
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
#ifdef SUBLIME
freopen("inputf.in", "r", stdin);
freopen("outputf.out", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
int n, w;
cin >> w >> n;
vector <pair <long long int, long long int>> obj;
for (int i = 0; i < n; i++) {
long long int wt, val, copy;
cin >> val >> wt >> copy;
for (long long int p = 1; copy; p <<= 1) {
long long int take = min(p, copy);
obj.push_back({take * val, take * wt});
copy -= take;
}
}
n = obj.size();
vector <vector <long long int>> dp(n + 1, vector <long long int> (w + 1));
for (int no = 1; no <= n; no++) {
auto [val, wt] = obj[no - 1];
for (int rw = 0; rw <= w; rw++) {
dp[no][rw] = dp[no - 1][rw];
if (rw >= wt)
dp[no][rw] = max(dp[no][rw], dp[no - 1][rw - wt] + val);
}
}
cout << *max_element(dp[n].begin(), dp[n].end());
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... |