#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);
int prev = 1;
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++)
for (int j = 0; j < cnt[i]; j++)
for (int weight = s; weight >= w[i]; weight--) {
if (dp[weight] < dp[weight - w[i]] + p[i]) {
dp[weight] = dp[weight - w[i]] + p[i];
ans = max(ans, dp[weight]);
}
}
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... |