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;
const int N=10005;
long long v[N],w[N],dp[N][N],k[N];
int main() {
int s,n;
cin>>s>>n;
for(int i=1; i<=n; i++){
cin>>v[i]>>w[i]>>k[i]; /// v[i]_value w[i]_weight
}
for(int i=0; i<=n; i++){/// i_ramdeni itemi shedis j_ra masa eteva
for(int j=0; j<=s; j++){
if(i==0 or j==0 ){
dp[i][j]=0;
continue;
}
dp[i][j]=dp[i-1][j]; /// tu nivti ar aviget;
for(int count=1; count<=k[i]; count++){
if(j-count*w[i]<0) break;
dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]*count]+v[i]*count);
}
}
}
cout<<dp[n][s]<<endl;
}
# | 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... |