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;
int w[n+1],v[n+1];
for (int i = 1; i <= n; i++)
{
int tk;
cin>>v[i]>>w[i]>>tk;
}
int dp[n+1][s+1];
for (int i = 0; i <= s; i++)
{
dp[0][i]=0;
}
for (int i = 0; i <= n; i++)
{
dp[i][0]=0;
}
for (int i = 1; i <= n; 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[n][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... |