当时脑子一片混乱,想到用栈写,但是没有想用优先队列写,这题用优先队列就十分的方便
解题思路 : 首先找出需要最少的人数,然后不挂失安静还是吵闹的我都可以任意排,找出最大的值加上去就可以了。
#include"bits/stdc++.h"
#define ll long long
#define pi pair<int,int>
#define inf 0x3f3f3f3f
#define _for(i,a,b) for(int i=a;i<=b;i++)
#define for_(i,a,b) for(int i=a;i<b;i++)
#define _fr(i,a,b) for(int i=a;i>=b;i--)
#define fr_(i,a,b) for(int i=a;i>b;i--)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
const int N = 1e4+5;
const ll mod = 1e9+7;
const double lp=1.000000011;
map<string,int>mp;
int A[N];
bool cmp(int j, int k){
return j>k;
}
void solve(){
int a,b,n,x;
cin >> a >> b >> n;
priority_queue<ll>q;
_for(i,1,a) cin >> A[i];
_for(i,1,b){
cin >> x;
q.push(x);
}
if((n+1)/2>a){
cout << -1 << endl;
return;
}
sort(A+1,A+1+a,cmp);
ll ans = 0;
int l = (n+1)/2;
_for(i,1,l) ans+=A[i];
_for(i,l+1,a) q.push(A[i]);
int p = n - l;
while (p--){
ans += q.top();
q.pop();
}
cout << ans << endl;
}
int main() {
int _;
cin >> _;
while (_--){
solve();
}
return 0;
}