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 <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int s, n;
cin >> s >> n;
if (n == 1)
{
int v, w; ll k;
cin >> v >> w >> k;
int m = s / w;
if (m <= k)
cout << v * m << '\n';
else
cout << v * k << '\n';
return 0;
}
vector<int> v, w;
for (int i = 0; i < n; ++i)
{
int val, wt;
ll k;
cin >> val >> wt >> k;
v.insert(v.end(), k, val);
w.insert(w.end(), k, wt);
}
int sz = v.size();
vector<vector<int>> dp(sz + 1, vector<int>(s + 1, 0));
for (int i = 1; i <= sz; ++i)
{
for (int j = 1; j <= s; ++j)
{
dp[i][j] = dp[i - 1][j];
if (j >= w[i - 1])
dp[i][j] =
max(dp[i - 1][j - w[i - 1]] + v[i - 1],
dp[i][j]);
}
}
cout << dp[sz][s] << '\n';
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... |