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
using namespace std;
const int INF = 1e9;
int val[100001], weight[100001], stock[100001];
int dp[101][2001][11];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int s, n;
cin >> s >> n;
stock[0] = 0;
for (int i = 1; i <= n; i++)
{
cin >> val[i] >> weight[i] >> stock[i];
}
for (int i = 1; i <= n; i++)
{
for (int j = 0; j <= s; j++)
{
for (int k = 1; k <= stock[i]; k++)
{
dp[i][j][k] = dp[i - 1][j][stock[i - 1]];
if (j - weight[i] >= 0)
{
if (k > 1)
{
dp[i][j][k] = max(dp[i][j][k], dp[i][j - weight[i]][k - 1] + val[i]);
}
else
{
dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - weight[i]][stock[i - 1]] + val[i]);
}
}
}
}
}
cout << dp[n][s][stock[n]] << endl;
return 0;
}
# | 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... |