fork(1) download
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define GG ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main () { GG;
int t; cin>>t;
while(t--){
ll n,m,s=0; 
cin>>n>>m; ll a[n],b[m]; 
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<m;i++) cin>>b[i];
sort(a,a+n);
sort(b,b+m);

ll mn=min(n,m),k=mn;
int j=m-1;
while(k--)
{ s+=b[j];
  j--;
}

for(int i=mn;i<n;i++)
s+=a[i];

cout<<s<<"\n";
}return 0;}
Success #stdin #stdout 0.01s 5304KB
stdin
1
1 2
2
10 1
stdout
10