1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| #include<iostream> #include<cstdio> #include<queue> #define fi first #define se second using namespace std; using ll=long long; using PII=pair<int,int>; const int N=2e5+10,INF=1e9+10; template <class T> inline void read(T &x) { x=0;int f=0; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();}; while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); if(f)x=~x+1; } template<class T,class ...T1> inline void read(T &x,T1 &...x1) { read(x),read(x1...); } int T,n,k,l; int a[N],b[N]; bool va[N],vb[N]; ll ans; priority_queue<PII>q[5]; inline void geta(int i){if(!vb[i])q[4].push({b[i],i});} inline void getb(int i){if(!va[i])q[3].push({a[i],i});} inline void solve() { read(n,k,l); ans=0; for(int i=0;i<5;i++)while(!q[i].empty())q[i].pop(); for(int i=1;i<=n;i++)read(a[i]),va[i]=0; for(int i=1;i<=n;i++)read(b[i]),vb[i]=0; for(int i=1;i<=n;i++)q[0].push({a[i]+b[i],i}),q[1].push({a[i],i}),q[2].push({b[i],i}); while(k--) { int type=-1,res=-INF; int s=-INF,fa=-INF,fb=-INF,sa=-INF,sb=-INF; while(!q[0].empty()&&(va[q[0].top().se]||vb[q[0].top().se]))q[0].pop(); if(!q[0].empty())s=q[0].top().fi; while(!q[1].empty()&&va[q[1].top().se])q[1].pop(); if(!q[1].empty())fa=q[1].top().fi; while(!q[2].empty()&&vb[q[2].top().se])q[2].pop(); if(!q[2].empty())fb=q[2].top().fi; while(!q[3].empty()&&(va[q[3].top().se]||!vb[q[3].top().se]))q[3].pop(); if(!q[3].empty())sa=q[3].top().fi; while(!q[4].empty()&&(!va[q[4].top().se]||vb[q[4].top().se]))q[4].pop(); if(!q[4].empty())sb=q[4].top().fi;
if(l<=k&&fa+fb>=res)res=fa+fb,type=1; if(fa+sb>=res)res=fa+sb,type=2; if(sa+fb>=res)res=sa+fb,type=3; if(sa+sb>=res)res=sa+sb,type=4; if(s>=res)res=s,type=0; if(type==-1)break; ans+=res; if(type==0)va[q[0].top().se]=vb[q[0].top().se]=1,l--; if(type==1)va[q[1].top().se]=vb[q[2].top().se]=1,geta(q[1].top().se),getb(q[2].top().se); if(type==2)va[q[1].top().se]=vb[q[4].top().se]=1,l--,geta(q[1].top().se); if(type==3)va[q[3].top().se]=vb[q[2].top().se]=1,l--,getb(q[2].top().se); if(type==4)va[q[3].top().se]=vb[q[4].top().se]=1,l-=2; } printf("%lld\n",ans); } int main() { read(T); while(T--)solve(); return 0; }
|