#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int S, N;
cin >> S >> N;
vector<ll> dp(S + 1, 0);
for (int i = 0; i < N; i++) {
int v, w, k;
cin >> v >> w >> k;
for (int cnt = 1; cnt <= k; cnt++) {
for (int j = S; j >= w; j--) {
if (j >= cnt * w)
dp[j] = max(dp[j], dp[j - cnt * w] + 1LL * cnt * v);
}
}
}
cout << *max_element(dp.begin(), dp.end()) << "\n";
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... |