#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<ll> 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);
for (int i = 0; i < n; i++) {
int K = cnt[i];
int gr = 1;
while (K) {
int br = min(gr, K);
K -= br;
gr >>= 1;
ll weight = br * w[i], price = br * p[i];
for (int j = s; j >= weight; j--)
dp[j] = max(dp[j], dp[j - weight] + price);
}
}
cout << *max_element(dp.begin(), dp.end()) << 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... |