| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1346115 | nguthianmangcay | Knapsack (NOI18_knapsack) | C++20 | 0 ms | 344 KiB |
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+3;
const int W=2e3+3;
const int K = 1e5+3;
const long long inf=1e18+3;
#define ll long long
#define fi first
#define se second
#define VOI void
#define int long long
vector<int>cand[W];
int v[N],w[N],k[N];
int nv[K],nw[K];
VOI jiangly(){
int W,n;
cin>>W>>n;
for(int i=1;i<=n;i++){
cin>>v[i]>>w[i]>>k[i];
cand[w[i]].push_back(i);
}
int sum_cnt = 0;
for(int wa=1;wa<=W;wa++){
int max_cnt = W/wa;
int cur_cnt = 0;
for(int i : cand[wa]){
while(cur_cnt < max_cnt && k[i] > 0){
nv[++sum_cnt] = v[i];
nw[sum_cnt] = w[i];
cur_cnt++;
k[i]--;
}
}
}
vector<ll>pre(W+2,0);
vector<ll>cur(W+2,0);
for(int i=1;i<=sum_cnt;i++){
for(int w=0;w<=W;w++){
cur[w] = pre[w];
if(w >= nw[i]){
cur[w] = max(cur[w],pre[w-nw[i]] + nv[i]);
}
}
pre.swap(cur);
cur.assign(W+2,0);
}
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();
// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
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... | ||||
