#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define size(x) (int)(x).size()
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int s, n;
cin >> s >> n;
vector<int> dp(s + 1);
for(int i = 0; i < n; i++) {
int v, w, k;
cin >> v >> w >> k;
for(int id = 1; k > 0; id <<= 1) {
int take = min(id, k);
k -= id;
for(int j = s; j >= w * take; j--) {
dp[j] = max(dp[j], dp[j - w * take] + v * take);
}
}
}
cout << dp[s];
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... |