This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
ll s,n;
cin>>s>>n;
vector<ll>ws;
vector<ll>vs;
vector<ll>vk;
vk.push_back(0);
vs.push_back(0);
ws.push_back(0);
for(ll i=0;i<n;i++){
ll v,w,k;
cin>>v>>w>>k;
ws.push_back(w);
vs.push_back(v);
vk.push_back(k);
}
vector<vector<ll>>dp(s+1,vector<ll>(n+1,0));
for(ll j=1;j<=s;j++){
for(int i=1;i<=n;i++){
for(int k=1;k<=vk[i];k++){
if(j>=(k*ws[i])){
dp[j][i]=max(dp[j][i],dp[j-(k*ws[i])][i-1]+(vs[i]*k));
}else{
break;
}
}
dp[j][i]=max(dp[j][i],dp[j][i-1]);
}
}
cout<<dp[s][n]<<endl;
return 0;
}
/*
20 3
5000 15 1
100 1 3
50 1 4
*/
# | 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... |