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;
int main()
{
int s, n;
cin >> s >> n;
vector<vector<int>> a(n, vector<int>(3)); // w,v,k
for (int i = 0; i < n; i++)
{
cin >> a[i][1] >> a[i][0] >> a[i][2];
a[i][1] = -a[i][1];
}
sort(a.begin(), a.end());
vector<int> w;
vector<int> v;
int rm = 0, ct = 0;
for (int i = 0; i < n; i++)
{
if ((i == 0) || (a[i][0] != a[i - 1][0]))
{
rm = s / a[i][0];
ct = min(a[i][2], rm);
for (int j = 0; j < ct; j++)
{
w.push_back(a[i][0]);
v.push_back(-a[i][1]);
}
rm -= ct;
}
else
{
ct = min(a[i][2], rm);
for (int j = 0; j < ct; j++)
{
w.push_back(a[i][0]);
v.push_back(-a[i][1]);
}
rm -= ct;
}
}
int nn = w.size();
vector<int> dp(s + 1, 0);
for (int i = 0; i < nn; i++)
{
for (int j = s; j >= w[i]; j--)
{
dp[j] = max(dp[j], v[i] + dp[j - w[i]]);
}
}
cout << dp[s] << 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... |