#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long w, n;
cin >> w >> n;
vector<priority_queue<pair<long long, long long>>> a(w + 1);
for (long long i = 0; i < n; i++) {
long long v, x, y;
cin >> v >> y >> x;
a[y].push({v, x});
}
vector<long long> d(w + 1);
for (long long i = 1; i <= w; i++) {
long long f = w / i;
while (!a[i].empty() && f) {
auto [v, x] = a[i].top();
a[i].pop();
if (x > f) x = f;
f -= x;
for (long long j = 0; j < x; j++) {
for (long long k = w; k >= i; k--) {
d[k] = max(d[k], d[k - i] + v);
}
}
}
}
cout << *max_element(d.begin(), d.end());
}
# | 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... |