#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int s, n; cin >> s >> n;
int v[n], w[n], k[n];
vector<multiset<int>> mx(s + 1);
for (int i = 0; i < n; ++i) {
cin >> v[i] >> w[i] >> k[i];
while (k[i]--) {
if (mx[w[i]].size() < s / w[i] || *mx[w[i]].begin() < v[i]) {
mx[w[i]].insert(v[i]);
if (mx[w[i]].size() > s / w[i])
mx[w[i]].erase(mx[w[i]].begin());
} else break;
}
}
int dp[s + 1];
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= s; ++i)
for (int x : mx[i])
for (int p = s; p >= i; --p)
dp[p] = max(dp[p - i] + x, dp[p]);
cout << *max_element(dp, dp + s + 1);
}
# | 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... |