#include <bits/stdc++.h>
using namespace std;
int main() {
long long s, n;
cin >> s >> n;
vector<tuple<long long, long long, long long>> in(n);
for (int i = 0; i < n; i++) {
long long v, w, z;
cin >> v >> w >> z;
in[i] = {v, w, z};
}
vector<vector<long long>> dp(s + 1, vector<long long>(n + 1, 0));
for (int j = 1; j <= n; j++) {
auto [v, w, z] = in[j - 1];
for (int i = 0; i <= s; i++) {
if (w <= i) {
dp[i][j] = max(dp[i][j - 1], dp[i - w][j - 1] + v);
} else {
dp[i][j] = dp[i][j - 1];
}
}
}
cout << dp[s][n] << 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... |