QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#689964 | #7739. Knapsack | i_love_qingyu | WA | 0ms | 3836kb | C++20 | 933b | 2024-10-30 19:27:53 | 2024-10-30 19:27:54 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct node{
long long int v,w;
}e[1000005];
bool cmp(struct node a,struct node b){
return a.v<b.v;
}
long long dp[10004];
int main()
{
int n,m,k;
long long ans=0;
cin>>n>>m>>k;
for(int i=1;i<=n;i++)cin>>e[i].v>>e[i].w;
sort(e+1,e+1+n,cmp);
vector<ll> suf(n+2);
priority_queue<ll,vector<ll>,greater<ll> > pq;
ll sum = 0;
for(int i=n;i;--i){
pq.push(e[i].v);
sum += e[i].v;
while(pq.size() > k){
sum -= pq.top();
pq.pop();
}
suf[i] = sum;
}
for(int i=1;i<=n;i++)
for(int j=m;j>=e[i].v;j--){
dp[j]=max(dp[j-e[i].v]+e[i].w,dp[j]);
ans=max(ans,dp[j]+suf[i+1]);
}
cout<<ans;
return 0;
}
/*
5 13 2
5 16
5 28
7 44
8 15
8 41
4 10 1
9 10
10 1
3 5
5 20
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3836kb
input:
4 10 1 9 10 10 1 3 5 5 20
output:
35
result:
ok 1 number(s): "35"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3832kb
input:
5 13 2 5 16 5 28 7 44 8 15 8 41
output:
88
result:
wrong answer 1st numbers differ - expected: '129', found: '88'