This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 5e2 + 5, inf = 1e9, mod = 998244353;
int dp[100006][2005], s, n;
pair<int, pair<int, int>> arr[100005];
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
cin >> s >> n;
for (int i = 1; i <= n; i++)
cin >> arr[i].first >> arr[i].second.first >> arr[i].second.second;
for (int i = 1; i <= n; i++)
for (int j = 0; j <= s; j++)
dp[i][j] = -inf;
for (int i = 1; i <= n; i++)
for (int j = 0; j <= s; j++)
for (int k = 0; k <= arr[i].second.second && k * arr[i].second.first <= j; k++)
dp[i][j] = max(dp[i][j], dp[i - 1][j - k * arr[i].second.first] + arr[i].first * k);
cout << dp[n][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... |