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<int>v,w;
int banyak=0;
int tv,tw,tk;
for (int i = 1; i <= n; i++)
{
cin>>tv>>tw>>tk;
banyak+=tk;
while (tk--)
{
v.push_back(tv);
w.push_back(tw);
}
}
int dp[banyak+1][s+1];
for (int i = 0; i <= s; i++)
{
dp[0][i]=0;
}
for (int i = 0; i <= banyak; i++)
{
dp[i][0]=0;
}
for (int i = 1; i <= banyak; i++)
{
for (int j = 1; j <= s; j++)
{
if(w[i]>j){
dp[i][j]=dp[i-1][j];
}else{
dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
}
}
}
cout<<dp[banyak][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... |