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>
#define int long long int
#define mod 1000000007
using namespace std;
signed main()
{
// ios_base::sync_with_stdio(NULL);
// cin.tie(NULL);
// freopen("feast.in", "r", stdin);
// freopen("feast.out", "w", stdout);
int s, n;
cin >> s >> n;
int v[n], w[n], k[n];
for (int i = 0; i < n; i++)
{
cin >> v[i] >> w[i] >> k[i];
}
vector<pair<int, int>> dp(s + 1, {0, 0});
for (int i = 0; i < n; i++)
{
for (int j = 0; j <= s; j++)
dp[j].second = 0;
for (int j = w[i]; j <= s; j++)
{
if (dp[j - w[i]].second < k[i] && (v[i] + dp[j - w[i]].first) > dp[j].first)
dp[j] = {v[i] + dp[j - w[i]].first, dp[j - w[i]].second + 1};
}
}
cout << (*max_element(dp.begin(), dp.end())).first << "\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... |