题目是这个

// Problem: G. Knapsack
// Contest: Codeforces - The 2023 ICPC Asia Nanjing Regional Contest (The 2nd Universal Cup. Stage 11: Nanjing)
// URL: https://codeforces.com/gym/104821/problem/G
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<set>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ri register int
using namespace std;
typedef long long ll;
const int N=5e3+10,W=1e4+10;
ll n,w,k,res,ans,t,f[W];
struct node{ll w,v;}a[N];
multiset<ll> s;
inline bool cmp(const node &p1,const node &p2){return p1.w<p2.w;}
int main()
{
scanf("%lld %lld %lld",&n,&w,&k);
for(ri i=1;i<=n;i++) scanf("%lld %lld",&a[i].w,&a[i].v);
sort(a+1,a+n+1,cmp);
for(ri i=1;i<=n;i++) s.insert(a[i].v);
for(auto it=--s.end();;it--)
{
ans+=(*it); t++;
if(t==k||it==s.begin()) break;
}
for(ri i=1;i<=n-k;i++)
{
ll r=0;
for(ri j=w;j>=a[i].w;j--)
{
f[j]=max(f[j],f[j-a[i].w]+a[i].v);
r=max(r,f[j]);
}
auto tt=s.find(a[i].v);
s.erase(tt);
t=0,res=0;
for(auto it=--s.end();;it--)
{
res+=(*it); t++;
if(t==k||it==s.begin()) break;
}
ans=max(ans,r+res);
}
printf("%lld",ans);
return 0;
}