#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int S, N;
cin >> S >> N;
vector<long long> dp(S + 1, 0);
for (int i = 0; i < N; i++) {
int v, w;
long long k;
cin >> v >> w >> k;
for (long long p = 1; k > 0; p <<= 1) {
long long take = min(p, k);
k -= take;
int W = take * w;
long long V = take * v;
for (int s = S; s >= W; s--) {
dp[s] = max(dp[s], dp[s - W] + V);
}
}
}
cout << dp[S] << '\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... |