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<int> dp(s + 1);
for (int i = 0; i < n; i++)
{
for (int j = s; j >= w[i]; j--)
{
for (int l = 1; l <= min(k[i], (j / w[i])); l++)
{
dp[j] = max(dp[j], l * v[i] + dp[j - l * w[i]]);
}
}
}
cout << dp[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... |