#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++) {
long long V, W, K;
cin >> V >> W >> K;
// Binary splitting
long long count = 1;
while (K > 0) {
long long take = min(count, K);
long long weight = take * W;
long long value = take * V;
for (int j = S; j >= weight; j--) {
dp[j] = max(dp[j], dp[j - weight] + value);
}
K -= take;
count <<= 1;
}
}
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... |