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 ll long long
#define pii pair<int, int>
#define tiii tuple<int, int, int>
using namespace std;
int main()
{
int n, s;
cin >> s >> n;
vector<int> value(n), weight(n), capacity(n);
vector<int> dp(s);
for (int i = 0; i < n; i++)
{
cin >> value[i] >> weight[i] >> capacity[i];
}
for (int i = 0; i < n; i++)
{
for (int j = s; j > 0; j--)
{
//dp[j] = max(dp[j],dp[j - 1]);
if (j < weight[i])
continue;
for (int k = 1; k <= capacity[i]; k++)
{
if(k*weight[i] > j) break;
dp[j] = max(dp[j], dp[j - (k*weight[i])] + (k*value[i]));
}
}
}
int ma = 0;
for(int i = 0; i <= s; i++){
ma = max(ma, dp[i]);
}
cout << ma;
}
# | 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... |