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[106][2005], s, n;
pair<int, pair<int, int>> arr[105];
int main()
{
cin >> s >> n;
for (int i = 1; i <= n; i++)
cin >> arr[i].first >> arr[i].second.first >> arr[i].second.second;
dp[0][0] = 0;
for (int i = 1; i <= s; i++)
dp[0][i] = -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].second.first * k);
cout << dp[n][s] << "\n";
}
/*
15
*/
# | 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... |