| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1346114 | nguthianmangcay | Knapsack (NOI18_knapsack) | C++20 | 1096 ms | 47784 KiB |
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+3;
const int K=3e6+3;
const long long inf=1e18+3;
#define ll long long
#define fi first
#define se second
#define VOI void
#define int long long
int k[N],w[N],v[N];
ll nw[K],nv[K];
VOI jiangly(){
int n,W;
cin>>W>>n;
int cnt=0;
for(int i=1;i<=n;i++){
cin>>v[i]>>w[i]>>k[i];
int c=1;
while(k[i] > c){
k[i]-=c;
nw[++cnt]=c*w[i];
nv[cnt]=c*v[i];
c*=2;
}
if(k[i] >= 1){
nw[++cnt]=k[i]*w[i];
nv[cnt]=k[i]*v[i];
}
}
vector<ll>pre(W+2,0);
vector<ll>cur(W+2,0);
for(int i=1;i<=cnt;i++){
for(int j=1;j<=W;j++){
cur[j]=pre[j];
if(j >= nw[i]){
cur[j]=max(cur[j],pre[j-nw[i]]+nv[i]);
}
}
swap(pre,cur);
}
cout<<pre[W];
}
int32_t main(){
cin.tie(0)->sync_with_stdio(0);
if(fopen("QUANSENSEI.inp","r")){
freopen("O(0).inp","r",stdin);
}
// if(fopen("input.txt","r")){
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// }
jiangly();
}
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... | ||||
