QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#689961 | #7739. Knapsack | i_love_qingyu | Compile Error | / | / | C++20 | 937b | 2024-10-30 19:26:52 | 2024-10-30 19:26:52 |
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<int,vector<ll>,greater<int> > 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
In file included from /usr/include/c++/13/queue:66, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:157, from answer.code:1: /usr/include/c++/13/bits/stl_queue.h: In instantiation of ‘class std::priority_queue<int, std::vector<long long int>, std::greater<int> >’: answer.code:20:50: required from here /usr/include/c++/13/bits/stl_queue.h:522:67: error: static assertion failed: value_type must be the same as the underlying container 522 | static_assert(is_same<_Tp, typename _Sequence::value_type>::value, | ^~~~~ /usr/include/c++/13/bits/stl_queue.h:522:67: note: ‘std::integral_constant<bool, false>::value’ evaluates to false