#include <bits/stdc++.h>
#define int long long
using namespace std;
const long long N = 2e5 + 5;
int a[N];
int dp[N]; // stands for maximum sum and weight
struct item
{
int weight, value, quantity;
};
void solve()
{
int n, s;
cin >> s >> n;
vector<item> a(n);
for (int i = 0; i < n; i++)
{
cin >> a[i].value >> a[i].weight >> a[i].quantity;
a[i].quantity = min(a[i].quantity, s / a[i].weight);
}
for (auto j : a)
{
for (int loop = 0; loop < j.quantity; loop++)
{
for (int i = s; i >= j.weight; i--)
{
dp[i] = max(dp[i], dp[i - j.weight] + j.value);
}
}
}
// for (int i = 0; i < s; i++)
// {
// }
cout << dp[s] << ' ';
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++)
{
// cout << "Case #" << i << ':' << ' ';
solve();
cout << 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... |