#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int s, n;
cin >> s >> n;
vector<int> p(n), w(n), cnt(n);
for (ll i = 0; i < n; i++)
cin >> p[i] >> w[i] >> cnt[i];
vector<ll> dp(s + 1);
ll ans = 0;
for (int i = 0; i < n; i++) {
int K = cnt[i], get = 1;
while (K) {
int br = min(get, K);
K -= br;
get <<= 1;
ll weight = br * w[i], price = br * p[i];
for (int j = s; j >= weight; j--)
if (dp[j - weight] + price > dp[j]) {
dp[j] = dp[j - weight] + price;
ans = max(ans, dp[j]);
}
}
}
cout << ans << endl;
}
| # | 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... |