| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1354783 | askelad | Knapsack (NOI18_knapsack) | C++20 | 1095 ms | 500 KiB |
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void solve(int test){
int W,n;
cin>>W>>n;
ll dp[2][W+1]={};
#define c1 (bool)(i&1)
#define c2 (bool)(!c1)
int w,v,c;
for(int i=1;i<=n;i++){
cin>>v>>w>>c;
for(int r=0;r<w;r++){
deque<pair<ll, int>>dq;
for(int q = 0 , cur= r, sum=0; cur <= W; q++,cur+=w,sum+=v){
ll cur_val = dp[c2] [cur] - sum;
while(!dq.empty() && dq.back().first <= cur_val)dq.pop_back();
dq.push_back({cur_val,q});
if(dq.front().second < q-c)dq.pop_front();
dp[c1] [cur] = dq.front().first + sum ;
}
}
}
ll ans=0;
for(auto x:dp[n&1])ans=max(ans,x);
cout<<ans;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
// cin>>t;
for(int i=1;i<=t;i++)
solve(i);
}
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
