| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1331932 | piolk | Knapsack (NOI18_knapsack) | C++20 | 1095 ms | 16836 KiB |
#include <bits/stdc++.h>
using namespace std;
int s,n;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>s>>n;
vector<pair<long long,long long>> l;
for (int i=0;i<n;i++){
long long v,w,k;
cin>>v>>w>>k;
long long j=1;
while (j<=k){
l.push_back({j*v,j*w});
k-=j;
j<<=1;
}
if (k>0) l.push_back({k*v,k*w});
}
vector<long long> dp(s+7,-1); //max value with weight
dp[0]=0;
for (auto [v,w]:l){
for (int i=s;i>=w;i--){
if (dp[i-w]==-1) continue;
dp[i]=max(dp[i],dp[i-w]+v);
}
}
long long ans=0;
for (int i=0;i<=s;i++) ans=max(ans,dp[i]);
cout<<ans<<"\n";
return 0;
}| # | 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... | ||||
