# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
533641 | 900iqNoobie | Knapsack (NOI18_knapsack) | C++17 | 146 ms | 262148 KiB |
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;
typedef long long ll;
typedef long double ld;
int const mod=998244353;
ll dp[20002][2002];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin>>t;
while (t--){
int n,s,w,k;
ll va;
cin>>s>>n;
if (n==1){
cin>>va>>w>>k;
cout<<va*(min(k,s/w))<<"\n";
continue;
}
vector <pair<ll,int>> v;
v.push_back({(ll)0,0});
for (int i=0;i<n;i++){
cin>>va>>w>>k;
while (k--) v.push_back({va,w});
}
dp[0][0]=0;
for (int i=1;i<v.size();i++){
for (int j=0;j<=s;j++){
dp[i][j]=dp[i-1][j];
if ((v[i].second)<=j) dp[i][j]=max(dp[i][j],dp[i-1][j-(v[i].second)]+(v[i].first));
}
}
cout<<dp[v.size()-1][s]<<"\n";
}
return 0;
}
Compilation message (stderr)
# | 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... |