#include<bits/stdc++.h>
using namespace std;
#ifndef LOCAL
#define eprintf(...) fprintf(stderr, _VA_ARGS_)
#else
#define eprintf(...) 42
#endif
typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll , int> pli;
typedef pair<ll , ll> pll;
typedef long double ld;
typedef vector< int > vi;
typedef unsigned long long ull;
#define int ll
#define mp make_pair
#define fi first
#define se second
const int N = 2e5 + 10;
const int INF = 1e18;
struct info {
int value , home;
} a[N] , b[N] , c[N];
int n , L , K;
int ta[N] , tb[N] , Fa[N] , Fb[N];
struct mheap1 {
priority_queue< pii > Heap , Del;
inline void _push(pii x) {
Heap.push(x);
}
inline bool _empty() {
while (!Del.empty() && Heap.top() == Del.top()) {
Heap.pop();
Del.pop();
}
return Heap.empty();
}
inline void _del(pii x) {
Del.push(x);
}
inline pii _top() {
while (!Del.empty() && Heap.top() == Del.top()) {
Heap.pop();
Del.pop();
}
return Heap.top();
}
} A , B;
struct mheap2 {
priority_queue< pii , vector< pii > , greater< pii > > Heap , Del;
inline void _push(pii x) {
Heap.push(x);
}
inline bool _empty() {
while (!Del.empty() && Heap.top() == Del.top()) {
Heap.pop();
Del.pop();
}
return Heap.empty();
}
inline void _del(pii x) {
Del.push(x);
}
inline pii _top() {
while (!Del.empty() && Heap.top() == Del.top()) {
Heap.pop();
Del.pop();
}
return Heap.top();
}
} C , D;
template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x) {
T f = 1; x = 0;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
x *= f;
}
inline bool cmp(info a , info b) {
return a.value > b.value;
}
signed main() {
int T;
read(T);
while (T--) {
read(n); read(K); read(L);
for (int i = 1; i <= n; ++i) {
read(a[i].value);
a[i].home = i;
ta[i] = a[i].value;
}
for (int i = 1; i <= n; ++i) {
read(b[i].value);
b[i].home = i;
tb[i] = b[i].value;
}
for (int i = 1; i <= n; ++i)
Fa[i] = Fb[i] = 0;
sort(a + 1 , a + n + 1 , cmp);
sort(b + 1 , b + n + 1 , cmp);
ll ans = 0;
for (int i = 1; i <= K; ++i) {
ans += a[i].value + b[i].value;
Fa[a[i].home] = Fb[b[i].home] = 1;
}
int cnt = 0;
for (int i = 1; i <= K; ++i)
if (Fb[a[i].home]) ++cnt;
if (cnt >= L) {
printf("%lld\n" , ans);
continue;
}
for (int i = 1; i <= K; ++i) {
if (Fa[a[i].home] && Fb[a[i].home]) continue;
if (Fa[a[i].home] && !Fb[a[i].home]) {
A._push(mp(tb[a[i].home] , a[i].home));
C._push(mp(a[i].value , a[i].home));
}
if (Fb[b[i].home] && !Fa[b[i].home]) {
B._push(mp(ta[b[i].home] , b[i].home));
D._push(mp(b[i].value , b[i].home));
}
}
for (int i = 1; i <= L - cnt; ++i) {
int da , db;
if (A._empty() == 0 && D._empty() == 0) da = A._top().fi - D._top().fi;
else da = -INF;
if (B._empty() == 0 && C._empty() == 0) db = B._top().fi - C._top().fi;
else db = -INF;
if (da > db) {
ans += da;
pii x = A._top() , y = D._top();
A._del(x); D._del(y);
C._del(mp(ta[x.se] , x.se)); B._del(mp(ta[y.se] , y.se));
} else {
ans += db;
pii x = B._top() , y = C._top();
B._del(x); C._del(y);
D._del(mp(tb[x.se] , x.se)); A._del(mp(tb[y.se] , y.se));
}
}
printf("%lld\n" , ans);
}
return 0;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 51.31 us | 68 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #2 | 50.65 us | 64 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #3 | 56.43 us | 68 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #4 | 40.73 us | 60 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #5 | 66.64 us | 68 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #6 | 77.3 us | 68 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #7 | 83.82 us | 72 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #8 | 64.72 us | 68 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #9 | 263.36 us | 96 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #10 | 251.24 us | 92 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #11 | 1.007 ms | 208 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #12 | 2.851 ms | 476 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #13 | 3.438 ms | 516 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #14 | 3.586 ms | 544 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #15 | 3.575 ms | 544 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #16 | 3.608 ms | 556 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #17 | 8.154 ms | 952 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #18 | 33.025 ms | 5 MB + 656 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #19 | 72.359 ms | 18 MB + 404 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #20 | 71.464 ms | 18 MB + 840 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #21 | 70.369 ms | 16 MB + 280 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #22 | 146.289 ms | 20 MB + 864 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #23 | 160.422 ms | 21 MB + 984 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #24 | 251.138 ms | 28 MB + 496 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #25 | 229.261 ms | 28 MB + 696 KB | Wrong Answer | Score: 0 | 显示更多 |