#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int s, n;
vector<int> v, w, k;
vector<vector<int>> dp;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> s >> n;
if (n == 1) {
int a, b, c;
cin >> a >> b >> c;
int x = min(s / b, c);
cout << a * x << '\n';
return 0;
}
vector<int> tv, tw;
for (int i = 0; i < n; ++i) {
int a, b, m;
cin >> a >> b >> m;
for (int j = 0; j < m; ++j) {
tv.push_back(a);
tw.push_back(b);
}
}
v = tv;
w = tw;
n = w.size();
dp.resize(2, vector<int>(s + 1, 0));
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= s; ++j) {
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]]);
}
}
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... |