# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
830846 | howard0027 | Knapsack (NOI18_knapsack) | C++14 | 1080 ms | 16264 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;
vector<ll> V;
vector<ll> W;
ll T,n,dp[65000];
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>T>>n;
for(int i=1;i<=n;++i){
ll v,w,s;
cin>>v>>w>>s;
for(int j=1;j<=s;j*=2){
V.push_back(j*v);
W.push_back(j*w);
s-=j;
}
if(s){
V.push_back(s*v);
W.push_back(s*w);
}
}
for(int i=0;i<V.size();i++){
for(int j=T;j-W[i]>=0;j--){
dp[j]=max(dp[j],dp[j-W[i]]+V[i]);
}
}
cout<<dp[T];
}
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... |