#include<bits/stdc++.h>
using namespace std;
//#define int long long
const int N=2e5+5;
int T;
int n,k;
int a[N],b[N];
long long cnt;
struct node{
int fst,snd;
friend bool operator<(node x,node y){
if(x.fst==y.fst){
return x.snd>y.snd;
}
return x.fst<y.fst;
}
};
priority_queue<node>Q;
int main(){
cin.tie(0)->sync_with_stdio(0);
cin>>T;
while(T--){
cin>>n>>k;
cnt=0;
while(!Q.empty()){
Q.pop();
}
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
cin>>b[i];
}
for(int i=1;i<=n;i++){
Q.push({a[i],b[i]});
}
while(k--){
node u=Q.top(); Q.pop();
cnt+=u.fst;
Q.push({max(0,u.fst-u.snd),u.snd});
}
cout<<cnt<<"\n";
}
return 0;
}
猜测复杂度 O(n log n),不知为什么 TLE