#include <algorithm>
#include <chrono>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
cin.tie(0)->sync_with_stdio(0);
int s, n;
cin >> s >> n;
vector<int> v(1, 0), w(1, 0);
for (int i = 0; i < n; ++i) {
int a, b, c;
cin >> a >> b >> c;
for (int j = 0; j < min(c, 2000); ++j) {
v.push_back(a);
w.push_back(b);
}
}
n = v.size() - 1;
vector<vector<int>> dp(2, vector<int>(s + 1, 0));
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= s; ++j) {
if (i == 0 || j == 0) {
dp[1][j] = 0;
continue;
}
if (w[i] > j) {
dp[1][j] = dp[0][j];
} else {
dp[1][j] = max(dp[0][j], v[i] + dp[0][j - w[i]]);
}
}
swap(dp[0], dp[1]);
}
cout << dp[0][s] << '\n';
}
# | 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... |