#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int s, n; cin >> s >> n;
vector<int> dp(s + 1, 0);
while (n--) {
int v, w, k; cin >> v >> w >> k;
int i;
for (i = 1; (i * (i + 1) / 2) <= k && i * w <= s; ++i) {
for (int j = s; j >= i * w; --j) dp[j] = max(dp[j], dp[j - i * w] + i * v);
}
--i;
i = (k - (i * (i + 1) / 2));
for (int j = s; j >= i * w; --j) dp[j] = max(dp[j], dp[j - i * w] + i * v);
}
int res = 0;
for (int i : dp) res = max(res, i);
cout << res << '\n';
return 0;
}
# | 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... |