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, va, we, k;
cin >> s >> n;
if(n == 1) // Subtask 1;
{
cin >> va >> we >> k;
cout << min((s / we) * va, k * va);
} else //Subtask 2 - 3;
{
vector<int> p;
vector<int> w;
for(int i = 0; i < n; i++) {
cin >> va >> we >> k;
while(k--)
{
p.push_back(va);
w.push_back(we);
}
}
int k = p.size() + 1;
long long dp[k][s + 1];
for(int i = 0; i <= s; i++)
dp[0][i] = 0;
for(int i = 1; i <= k - 1; i++)
{
for(int a = 0; a <= s; a++)
{
if(a - w[i - 1] >= 0)
dp[i][a] = max(dp[i - 1][a], dp[i - 1][a - w[i -1]] + p[i - 1]);
else
dp[i][a] = dp[i - 1][a];
}
}
cout << dp[k - 1][s];
}
}
# | 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... |