#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int S, N;
if (!(cin >> S >> N)) return 0;
vector<ll> dp(S + 1, 0);
for (int i = 0; i < N; ++i) {
ll v, w, k;
cin >> v >> w >> k;
k = min(k, (ll)S / w);
for (ll m = 1; k > 0; m <<= 1) {
ll num = min(m, k);
ll total_v = num * v;
ll total_w = num * w;
for (int j = S; j >= total_w; --j) {
dp[j] = max(dp[j], dp[j - (int)total_w] + total_v);
}
k -= num;
}
}
ll result = 0;
for (int j = 0; j <= S; ++j) {
result = max(result, dp[j]);
}
cout << result << endl;
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... |