QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#671646 | #7739. Knapsack | wangxiaorui# | WA | 0ms | 3716kb | C++14 | 943b | 2024-10-24 13:52:17 | 2024-10-24 13:52:17 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5010;
int n,W,k;
ll f[10010];
ll ans;
ll suf[10010];
struct node{
int w,v;
}a[N];
bool cmp(node x,node y){
return x.w<y.w;
}
priority_queue <int,vector<int>,greater<int> > q;
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n>>W>>k;
for(int i=1;i<=n;i++) cin>>a[i].w>>a[i].v;
sort(a+1,a+1+n,cmp);
ll sum=0;
for(int i=n-k+1;i<=n;i++){
sum+=a[i].v;q.push(a[i].v);
suf[n-k+1]=sum;
}
for(int i=n-k;i>=1;i--){
if(q.top()<a[i].v){
sum-=q.top();sum+=a[i].v;
q.push(a[i].v);
}
suf[i]=sum;
}
ans=max(ans,suf[1]);
for(int i=1;i<=n-k;i++){
for(int j=W;j>=a[i].w;j--)
f[j]=max(f[j],f[j-a[i].w]+a[i].v);
ans=max(ans,f[W]+suf[i+1]);
}
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
input:
4 10 1 9 10 10 1 3 5 5 20
output:
35
result:
ok 1 number(s): "35"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
5 13 2 5 16 5 28 7 44 8 15 8 41
output:
129
result:
ok 1 number(s): "129"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3716kb
input:
10 50 1 44 182173741 38 163268500 36 114173760 30 521894533 25 89514235 12 516184197 42 971377551 35 28242326 31 480227821 31 388523197
output:
2513859817
result:
wrong answer 1st numbers differ - expected: '2009456281', found: '2513859817'