# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
533649 | 900iqNoobie | Knapsack (NOI18_knapsack) | C++17 | 1069 ms | 132968 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[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;
int r=(s/w);
k=min(k,r);
r=1;
while (k-r>=0){
v.push_back({va*r,w*r});
k-=r;
r++;
}
if (k) v.push_back({va*k,w*k});
}
for (int i=1;i<v.size();i++){
for (int j=s;j>=v[i].second;j--){
dp[j]=max(dp[j],v[i].first+dp[j-v[i].second]);
}
}
cout<<dp[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... |