Rahul and Ankit are the only two waiters in the Royal Restaurant. Today, the restaurant received n orders. The amount of tips may differ when handled by different waiters, if Rahul takes the i_{th} order, he would be tipped a_{i} rupees and if Ankit takes this order, the tip would be b_{i} rupees.
In order to maximize the total tip value they decided to distribute the order among themselves. One order will be handled by one person only. Also, due to time constraints Rahul cannot take more than x orders and Ankit cannot take more than y orders. It is guaranteed that x + y is greater than or equal to n, which means that all the orders can be handled by either Rahul or Ankit. Find out the maximum possible amount of total tip money after processing all the orders.
Example 1:
Input:
n = 5, x = 3, y = 3
a[] = {1, 2, 3, 4, 5}
b[] = {5, 4, 3, 2, 1}
Output: 21
Explanation: Rahul will serve 3rd, 4th 
and 5th order while Ankit will serve 
the rest.
Example 2:
Input:
n = 8, x = 4, y = 4
a[] = {1, 4, 3, 2, 7, 5, 9, 6}
b[] = {1, 2, 3, 6, 5, 4, 9, 8}
Output: 43
Explanation: Rahul will serve 1st, 2nd, 5th 
and 6th order while Ankit will serve the rest.
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxTip() which takes array a[ ], array b[ ], n, x and y as input parameters and returns an integer denoting the answer.
Expected Time Complexity: O(n*logn)
Expected Auxiliary Space: O(n)
Constraints:
1 ≤ n ≤ 10^{5}
1 ≤ x, y ≤ N
x + y ≥ n
1 ≤ a[i], b[i] ≤ 10^{5}

Difficulty: MEDIUM
Tags: Dynamic programming

Data structures
Skill types: Dynamic programming

Data structures
Expected Time Complexity: O(n*logn)
Expected Auxiliary Space: O(n)

Starter code:
#User function Template for python3



class Solution:
    def maxTip(self, a, b, n, x, y):
        # code here

Solutions:
class Solution:

	def maxTip(self, a, b, n, x, y):
		mx = 0
		diff_contribution = [abs(a[index] - b[index]) for index in range(n)]
		diff_contribution = sorted(enumerate(diff_contribution), key=lambda d: -d[1])
		diff_index = [d[0] for d in diff_contribution]
		for index_value in diff_index:
			if a[index_value] >= b[index_value] and x:
				mx += a[index_value]
				x -= 1
			elif a[index_value] < b[index_value] and y:
				mx += b[index_value]
				y -= 1
			elif not x and y:
				mx += b[index_value]
				y -= 1
			elif not y and x:
				mx += a[index_value]
				x -= 1
		return mx


class Solution:

	def maxTip(self, a, b, n, x, y):
		lis = []
		for i in range(n):
			lis.append([abs(a[i] - b[i]), i])
		lis.sort(key=lambda x: x[0], reverse=True)
		ans = 0
		for i in lis:
			idx = i[1]
			if x > 0 and y > 0:
				if a[idx] > b[idx]:
					ans += a[idx]
					x -= 1
				elif a[idx] == b[idx]:
					if x > y:
						ans += a[idx]
						x -= 1
					else:
						ans += a[idx]
						y -= 1
				else:
					ans += b[idx]
					y -= 1
			elif x > 0:
				ans += a[idx]
				x -= 1
			elif y > 0:
				ans += b[idx]
				y -= 1
		return ans


class Solution:

	def maxTip(self, a, b, n, x, y):
		ans = 0
		arrs = []
		for i in range(n):
			temp = []
			temp.append(abs(a[i] - b[i]))
			temp.append(a[i])
			temp.append(b[i])
			arrs.append(temp)
		arrs.sort()
		for i in range(n - 1, -1, -1):
			if arrs[i][1] >= arrs[i][2]:
				if x > 0:
					ans += arrs[i][1]
					x -= 1
				else:
					ans += arrs[i][2]
			elif y > 0:
				ans += arrs[i][2]
				y -= 1
			else:
				ans += arrs[i][1]
				x -= 1
		return ans


class Solution:

	def maxTip(self, a, b, n, x, y):
		arr = []
		one = 0
		two = 0
		for i in range(n):
			arr.append([a[i], b[i], a[i] - b[i], b[i] - a[i]])
			if arr[i][2] < 0:
				two += 1
			else:
				one += 1
		arr.sort(key=lambda x: x[2], reverse=True)
		cost = 0
		i = 0
		a = x
		if x + y > n:
			a = x - (x + y - n)
		while a and i < n:
			cost += arr[i][0]
			a -= 1
			i += 1
		a = x + y - n
		while a and i < n:
			if arr[i][0] > arr[i][1]:
				cost += arr[i][0]
			else:
				cost += arr[i][1]
			i += 1
			a -= 1
		while y and i < n:
			cost += arr[i][1]
			y -= 1
			i += 1
		return cost


class Solution:

	def maxTip(self, a, b, n, x, y):
		tip = 0
		d = list()
		for i in range(n):
			d.append([abs(a[i] - b[i]), i])
		d.sort(reverse=True)
		for i in range(n):
			if a[d[i][1]] >= b[d[i][1]]:
				if x > 0:
					tip += a[d[i][1]]
					x -= 1
				elif y > 0:
					tip += b[d[i][1]]
					y -= 1
			elif b[d[i][1]] >= a[d[i][1]]:
				if y > 0:
					tip += b[d[i][1]]
					y -= 1
				elif x > 0:
					tip += a[d[i][1]]
					x -= 1
		return tip


class Solution:

	def maxTip(self, a, b, n, x, y):
		l = []
		for i in range(n):
			l.append([a[i], b[i], abs(a[i] - b[i])])
		l.sort(reverse=True, key=lambda x: x[2])
		res = 0
		for i in range(n):
			if x <= 0:
				res += l[i][1]
			elif y <= 0:
				res += l[i][0]
			elif l[i][0] > l[i][1]:
				res += l[i][0]
				x -= 1
			else:
				res += l[i][1]
				y -= 1
		return res


class Solution:

	def maxTip(self, A, B, N, X, Y):
		tips = []
		for i in range(N):
			tips.append((A[i], B[i]))
		tips.sort(key=lambda x: -abs(x[0] - x[1]))
		ans = 0
		for i in range(N):
			if Y == 0 or (X > 0 and tips[i][0] >= tips[i][1]):
				ans += tips[i][0]
				X -= 1
			else:
				ans += tips[i][1]
				Y -= 1
		return ans


class Solution:

	def maxTip(self, a, b, n, x, y):
		tip = 0
		d = {}
		for i in range(n):
			if a[i] == b[i]:
				tip += a[i]
				continue
			d[i] = abs(a[i] - b[i])
		d = sorted(d.items(), key=lambda item: item[1], reverse=True)
		for i in d:
			ind = i[0]
			val = max(a[ind], b[ind])
			if val == a[ind]:
				if x:
					tip += val
					x -= 1
				else:
					tip += b[ind]
					y -= 1
			elif val == b[ind]:
				if y:
					tip += val
					y -= 1
				else:
					tip += a[ind]
					x -= 1
		return tip


class Solution:

	def maxTip(self, a, b, n, x, y):

		def compare(val):
			return val[0]
		Pair = []
		for i in range(n):
			Pair.append([abs(a[i] - b[i]), i])
		Pair.sort(key=compare, reverse=True)
		ans = 0
		for i in range(n):
			indx = Pair[i][1]
			if a[indx] > b[indx]:
				if x > 0:
					ans += a[indx]
					x -= 1
				elif y > 0:
					ans += b[indx]
					y -= 1
			elif y > 0:
				ans += b[indx]
				y -= 1
			elif x > 0:
				ans += a[indx]
				x -= 1
		return ans


class Solution:

	def maxTip(self, a, b, n, x, y):
		arr = [(a[i], b[i]) for i in range(n)]
		arr.sort(key=lambda x: abs(x[0] - x[1]), reverse=True)
		t = 0
		for i in range(n):
			if arr[i][0] >= arr[i][1]:
				if x > 0:
					t += arr[i][0]
					x -= 1
				else:
					t += arr[i][1]
					y -= 1
			elif y > 0:
				t += arr[i][1]
				y -= 1
			else:
				t += arr[i][0]
				x += 1
		return t


class Solution:

	def maxTip(self, a, b, n, x, y):
		diff = [(a[i] - b[i], a[i], b[i]) for i in range(n)]
		diff.sort(reverse=True)
		(r_count, a_count) = (0, 0)
		for (d, ar, br) in diff:
			if d >= 0 and r_count < x:
				r_count += 1
			elif d < 0 and a_count < y:
				a_count += 1
			elif r_count < x:
				r_count += 1
			else:
				a_count += 1
		total_tip = sum((ar for (d, ar, br) in diff[:r_count]))
		total_tip += sum((br for (d, ar, br) in diff[r_count:r_count + a_count]))
		return total_tip


class Solution:

	def maxTip(self, a, b, n, x, y):
		arr = [(a[i] - b[i], a[i], b[i]) for i in range(n)]
		arr.sort()
		summa = 0
		while arr and x and (arr[-1][0] >= 0):
			summa += arr.pop()[1]
			x -= 1
		j = len(arr) - y
		for _ in range(j):
			summa += arr.pop()[1]
		summa += sum([item[2] for item in arr])
		return summa


class Solution:

	def maxTip(self, a, b, n, x, y):
		diff = [[a[i] - b[i], i] for i in range(n)]
		diff.sort()
		diff = diff[::-1]
		l = 0
		r = n - 1
		ans = 0
		while l <= r and x > 0 and (y > 0):
			if diff[l][0] >= abs(diff[r][0]):
				ans += a[diff[l][1]]
				l += 1
				x -= 1
			else:
				ans += b[diff[r][1]]
				r -= 1
				y -= 1
		while l <= r and x > 0:
			ans += a[diff[l][1]]
			l += 1
			x -= 1
		while l <= r and y > 0:
			ans += b[diff[r][1]]
			r -= 1
			y -= 1
		return ans


class Solution:

	def maxTip(self, a, b, n, x, y):
		ix = sorted(list(range(n)), key=lambda i: abs(a[i] - b[i]), reverse=True)
		ans = 0
		for i in ix:
			if x == 0:
				ans += b[i]
				y -= 1
			elif y == 0:
				ans += a[i]
				x -= 1
			elif a[i] >= b[i]:
				ans += a[i]
				x -= 1
			else:
				ans += b[i]
				y -= 1
		return ans


class Solution:

	def maxTip(self, a, b, n, x, y):
		arr = list()
		for i in range(n):
			arr.append([abs(a[i] - b[i]), a[i], b[i]])
		arr.sort(key=lambda i: i[0], reverse=True)
		ans = 0
		for val in arr:
			if val[1] > val[2] and x > 0:
				ans += val[1]
				x -= 1
			elif val[1] < val[2] and y > 0:
				ans += val[2]
				y -= 1
			elif x > y:
				ans += val[1]
				x -= 1
			elif x < y:
				ans += val[2]
				y -= 1
			else:
				ans += val[1]
				x -= 1
		return ans


class Solution:

	def maxTip(self, a, b, n, x, y):
		temp = []
		result = 0
		for i in range(n):
			temp.append([abs(a[i] - b[i]), i])
		temp.sort(reverse=True)
		for elem in temp:
			if a[elem[1]] > b[elem[1]]:
				if x > 0:
					result += a[elem[1]]
					x -= 1
				else:
					result += b[elem[1]]
					y -= 1
			elif y > 0:
				result += b[elem[1]]
				y -= 1
			else:
				result += a[elem[1]]
				x -= 1
		return result


import heapq

class Solution:

	def maxTip(self, a, b, n, x, y):
		pq = []
		res = 0
		for i in range(0, n):
			heapq.heappush(pq, [-abs(a[i] - b[i]), -a[i], -b[i]])
		while len(pq):
			(diff, r, a) = heapq.heappop(pq)
			(r, a) = (-r, -a)
			if r > a:
				if x > 0:
					res += r
					x -= 1
				else:
					res += a
					y -= 1
			elif y > 0:
				res += a
				y -= 1
			else:
				res += r
				x -= 1
		return res


import bisect

class Solution:

	def maxTip(self, a, b, n, x, y):
		dp = {}
		for i in range(n):
			dp[i] = a[i] - b[i]
		d = sorted(dp.items(), key=lambda x: x[1], reverse=True)
		r = 0
		ind = {}
		c = 0
		for i in range(x):
			if d[i][1] >= 0:
				c += 1
				ind[d[i][0]] = 1
				r += a[d[i][0]]
			elif n - c <= y:
				break
			else:
				c += 1
				ind[d[i][0]] = 1
				r += a[d[i][0]]
		for i in range(n):
			if i not in ind:
				r += b[i]
		return r


class Solution:

	def maxTip(self, a, b, n, x, y):
		combined_list = [(a[i], b[i]) for i in range(n)]
		combined_list.sort(reverse=True, key=lambda x: abs(x[0] - x[1]))
		total = 0
		for i in range(n):
			if x > 0 and (combined_list[i][0] > combined_list[i][1] or y <= 0):
				total += combined_list[i][0]
				x -= 1
			else:
				total += combined_list[i][1]
				y -= 1
		return total


class Solution:

	def maxTip(self, a, b, n, x, y):
		h = {}
		for i in range(n):
			k = abs(a[i] - b[i])
			h[i] = k
		l = sorted(h.items(), key=lambda x: x[1])
		l.reverse()
		count = 0
		for i in l:
			if a[i[0]] >= b[i[0]]:
				if x > 0:
					count += a[i[0]]
					x -= 1
				else:
					count += b[i[0]]
					y -= 1
			elif y > 0:
				count += b[i[0]]
				y -= 1
			else:
				count += a[i[0]]
				x -= 1
		return count


class Solution:

	def maxTip(self, a, b, n, x, y):
		arr = []
		(X, Y) = (0, 0)
		value = -1
		ans = 0
		for i in range(n):
			if a[i] == b[i]:
				ans += a[i]
			else:
				arr.append([a[i], b[i], abs(a[i] - b[i])])
		arr.sort(key=lambda i: i[2])
		arr = arr[::-1]
		flag = 0
		for i in range(len(arr)):
			if flag == 2 or (flag == 0 and arr[i][0] >= arr[i][1]):
				X += 1
				ans += arr[i][0]
				if X == x:
					flag = 1
			elif flag == 1 or (flag == 0 and arr[i][1] >= arr[i][0]):
				Y += 1
				ans += arr[i][1]
				if Y == y:
					flag = 2
		return ans


class Solution:

	def maxTip(self, a, b, n, x, y):
		dp = []
		for i in range(n):
			dp.append([abs(a[i] - b[i]), a[i], b[i]])
		dp.sort(reverse=True)
		ans = 0
		for i in range(n):
			(p, q) = (dp[i][1], dp[i][2])
			if x == 0:
				ans += q
			elif y == 0:
				ans += p
			elif p > q:
				ans += p
				x -= 1
			else:
				ans += q
				y -= 1
		return ans


class Solution:

	def maxTip(self, a, b, n, x, y):
		diff = [[a[i] - b[i], i] for i in range(n)]
		diff.sort()
		res = 0
		for i in range(n):
			if y > 0 and n - i > x:
				res += b[diff[i][1]]
				y -= 1
			elif y > 0 and n - i <= x and (diff[i][0] < 0):
				res += b[diff[i][1]]
				y -= 1
			elif y > 0 and n - i <= x and (diff[i][0] >= 0):
				res += a[diff[i][1]]
				x -= 1
			else:
				res += a[diff[i][1]]
				x -= 1
		return res


class Solution:

	def solve(self, a, b, x, y, i, dp):
		if i >= len(a):
			return 0
		if x == 0 and y == 0:
			return 0
		if (i, x, y) in dp:
			return dp[i, x, y]
		if x > 0 and y > 0:
			dp[i, x, y] = max(a[i] + self.solve(a, b, x - 1, y, i + 1, dp), b[i] + self.solve(a, b, x, y - 1, i + 1, dp))
			return dp[i, x, y]
		elif x > 0:
			dp[i, x, y] = a[i] + self.solve(a, b, x - 1, y, i + 1, dp)
			return dp[i, x, y]
		else:
			dp[i, x, y] = b[i] + self.solve(a, b, x, y - 1, i + 1, dp)
			return dp[i, x, y]

	def maxTip(self, a, b, n, x, y):
		arr = []
		for i in range(n):
			arr.append([a[i], b[i]])
		arr.sort(key=lambda x: abs(x[0] - x[1]))
		arr.reverse()
		i = 0
		ans = 0
		while x > 0 and y > 0 and (i < n):
			if arr[i][1] >= arr[i][0]:
				ans += arr[i][1]
				y -= 1
			else:
				ans += arr[i][0]
				x -= 1
			i += 1
		while i < n and x > 0:
			ans += arr[i][0]
			x -= 1
			i += 1
		while i < n and y > 0:
			ans += arr[i][1]
			y -= 1
			i += 1
		return ans


class Solution:

	def maxTip(self, a, b, n, x, y):
		res = 0
		arr = []
		for i in range(n):
			arr.append([abs(a[i] - b[i]), a[i], b[i]])
		arr.sort(reverse=True)
		for val in arr:
			if val[1] > val[2] and x > 0:
				res += val[1]
				x -= 1
			elif val[1] < val[2] and y > 0:
				res += val[2]
				y -= 1
			elif x >= y:
				res += val[1]
				x -= 1
			elif x < y:
				res += val[2]
				y -= 1
		return res


class Solution:

	def util(self, a, b, n, x, y, index, hm):
		if index >= n or x < 0 or y < 0:
			return 0
		key = str(index) + '_' + str(x) + '_' + str(y)
		if key in hm:
			return hm[key]
		if x > 0 and y > 0:
			dp = max(a[index] + self.util(a, b, n, x - 1, y, index + 1, hm), b[index] + self.util(a, b, n, x, y - 1, index + 1, hm))
		elif x > 0:
			dp = a[index] + self.util(a, b, n, x - 1, y, index + 1, hm)
		elif y > 0:
			dp = b[index] + self.util(a, b, n, x, y - 1, index + 1, hm)
		hm[key] = dp
		return dp

	def maxTip(self, a, b, n, x, y):
		diff = []
		for i in range(n):
			diff.append([abs(a[i] - b[i]), i])
		diff = sorted(diff)
		diff = diff[::-1]
		tip = 0
		for j in diff:
			index = j[1]
			if x > 0 and y > 0:
				tip += max(a[index], b[index])
				if a[index] >= b[index]:
					x -= 1
				else:
					y -= 1
			elif x > 0 and y <= 0:
				tip += a[index]
				x -= 1
			else:
				tip += b[index]
				y -= 1
		return tip


class Solution:

	def maxTip(self, a, b, n, x, y):
		(ans, vec) = (0, [(0, 0)] * n)
		for i in range(n):
			vec[i] = (a[i] - b[i], i)
		vec = sorted(vec, reverse=True)
		(lt, rt, l, r) = (0, 0, 0, n - 1)
		while lt + rt < n and lt < x and (rt < y):
			if vec[l][0] >= abs(vec[r][0]):
				ans += a[vec[l][1]]
				lt += 1
				l += 1
			else:
				ans += b[vec[r][1]]
				r -= 1
				rt += 1
		while lt + rt < n and lt < x:
			ans += a[vec[l][1]]
			l += 1
			lt += 1
		while lt + rt < n and rt < y:
			ans += b[vec[r][1]]
			r -= 1
			rt += 1
		return ans


import numpy as np

class Solution:

	def maxTip(self, a, b, n, x, y):
		diff = [0] * n
		for i in range(n):
			diff[i] = a[i] - b[i]
		xx = yy = 0
		diff = np.array(diff)
		a = np.array(a)
		b = np.array(b)
		idx = np.argsort(diff)
		a = a[idx]
		b = b[idx]
		diff = diff[idx]
		tip = 0
		idx0 = 0
		for i in range(n):
			if diff[i] == 0:
				idx0 = i
			elif diff[i] > 0:
				idx0 = i - 1
				break
		for i in range(n):
			if diff[i] > 0:
				tip += a[i]
				xx += 1
			else:
				tip += b[i]
				yy += 1
		if xx <= x and yy <= y:
			return tip
		elif xx > x:
			d = xx - x
			for i in range(d):
				tip -= diff[idx0 + 1 + i]
			return tip
		else:
			d = yy - y
			for i in range(d):
				tip += diff[idx0 - i]
			return tip


class Solution:

	def maxTip(self, a, b, n, x, y):
		ans = 0
		diff_pos = []
		for i in range(n):
			diff_pos.append([abs(a[i] - b[i]), i])
		diff_pos.sort(reverse=True)
		for i in range(n):
			if a[diff_pos[i][1]] >= b[diff_pos[i][1]]:
				if x > 0:
					ans += a[diff_pos[i][1]]
					x -= 1
				else:
					ans += b[diff_pos[i][1]]
					y -= 1
			elif y > 0:
				ans += b[diff_pos[i][1]]
				y -= 1
			else:
				ans += a[diff_pos[i][1]]
				x -= 1
		return ans


class Solution:

	def maxTip(self, a, b, n, x, y):
		tip = 0
		l = []
		for i in range(n):
			l.append([abs(a[i] - b[i]), i])
		l.sort(reverse=True)
		for i in range(n):
			if a[l[i][1]] >= b[l[i][1]]:
				if x > 0:
					tip += a[l[i][1]]
					x -= 1
				elif y > 0:
					tip += b[l[i][1]]
					y -= 1
			elif b[l[i][1]] >= a[l[i][1]]:
				if y > 0:
					tip += b[l[i][1]]
					y -= 1
				elif x > 0:
					tip += a[l[i][1]]
					x -= 1
		return tip
if __name__ == '__main__':
	tc = int(input())
	while tc > 0:
		(n, x, y) = list(map(int, input().strip().split()))
		a = list(map(int, input().strip().split()))
		b = list(map(int, input().strip().split()))
		ans = Solution().maxTip(a, b, n, x, y)
		print(ans)
		tc -= 1


class Solution:

	def maxTip(self, a, b, n, x, y):
		arr = []
		for i in range(n):
			arr.append([abs(a[i] - b[i]), a[i], b[i]])
		arr.sort(key=lambda x: x[0], reverse=True)
		ans = 0
		for val in arr:
			if val[1] > val[2] and x > 0:
				ans += val[1]
				x -= 1
			elif val[1] < val[2] and y > 0:
				ans += val[2]
				y -= 1
			elif x > y:
				ans += val[1]
				x -= 1
			elif x < y:
				ans += val[2]
				y -= 1
			else:
				ans += val[1]
				x -= 1
		return ans
if __name__ == '__main__':
	tc = int(input())
	while tc > 0:
		(n, x, y) = list(map(int, input().strip().split()))
		a = list(map(int, input().strip().split()))
		b = list(map(int, input().strip().split()))
		ans = Solution().maxTip(a, b, n, x, y)
		print(ans)
		tc -= 1


class Solution:

	def maxTip(self, a, b, n, x, y):
		tsum = 0
		s = sorted([i for i in zip(a, b)], key=lambda x: abs(x[0] - x[1]), reverse=True)
		i = 0
		tsum = 0
		for (ai, bi) in s:
			if ai > bi and x > 0:
				tsum += ai
				x -= 1
			elif bi > ai and y > 0:
				tsum += bi
				y -= 1
			else:
				tsum += min(ai, bi)
		return tsum
if __name__ == '__main__':
	tc = int(input())
	while tc > 0:
		(n, x, y) = list(map(int, input().strip().split()))
		a = list(map(int, input().strip().split()))
		b = list(map(int, input().strip().split()))
		ans = Solution().maxTip(a, b, n, x, y)
		print(ans)
		tc -= 1


class Solution:

	def maxTip(self, a, b, n, x, y):
		ans = 0
		i = 0
		r = 0
		an = 0
		s = list(zip(a, b))
		s = sorted(s, key=lambda x: abs(x[0] - x[1]), reverse=True)
		while i < n and (r < x and an < y):
			if s[i][0] > s[i][1]:
				ans += s[i][0]
				r += 1
			else:
				ans += s[i][1]
				an += 1
			i += 1
		if an < y:
			while i < n and an < y:
				ans += s[i][1]
				an += 1
				i += 1
		else:
			while i < n and r < x:
				ans += s[i][0]
				r += 1
				i += 1
		return ans
if __name__ == '__main__':
	tc = int(input())
	while tc > 0:
		(n, x, y) = list(map(int, input().strip().split()))
		a = list(map(int, input().strip().split()))
		b = list(map(int, input().strip().split()))
		ans = Solution().maxTip(a, b, n, x, y)
		print(ans)
		tc -= 1


class Solution:

	def maxTip(self, a, b, n, x, y):
		for i in range(n):
			A = a[i]
			B = b[i]
			a[i] = [A, abs(A - B)]
			b[i] = [B, abs(A - B)]
		tip = 0
		a.sort(reverse=True, key=lambda x: x[1])
		b.sort(reverse=True, key=lambda x: x[1])
		for i in range(n):
			if a[i][0] > b[i][0]:
				if x != 0:
					tip += a[i][0]
					x -= 1
				else:
					tip += b[i][0]
					y -= 1
			elif y != 0:
				tip += b[i][0]
				y -= 1
			else:
				tip += a[i][0]
				x -= 1
		return tip

		def fun(X, Y, ind):
			if ind == 0:
				return 0
			if (X, Y - 1, ind - 1) not in d:
				d[X, Y - 1, ind - 1] = fun(X, Y - 1, ind - 1)
			if (X - 1, Y, ind - 1) not in d:
				d[X - 1, Y, ind - 1] = fun(X - 1, Y, ind - 1)
			if X == 0:
				return d[X, Y - 1, ind - 1] + b[ind - 1]
			if Y == 0:
				return d[X - 1, Y, ind - 1] + a[ind - 1]
			return max(d[X - 1, Y, ind - 1] + a[ind - 1], d[X, Y - 1, ind - 1] + b[ind - 1])
		return fun(x, y, len(a))
if __name__ == '__main__':
	tc = int(input())
	while tc > 0:
		(n, x, y) = list(map(int, input().strip().split()))
		a = list(map(int, input().strip().split()))
		b = list(map(int, input().strip().split()))
		ans = Solution().maxTip(a, b, n, x, y)
		print(ans)
		tc -= 1


class Solution:

	def maxTip(self, a, b, n, x, y):
		sum = 0
		diff = [[abs(a[i] - b[i]), i] for i in range(n)]
		diff = sorted(diff, reverse=True)
		for i in range(n):
			if a[diff[i][1]] > b[diff[i][1]]:
				if x > 0:
					sum = sum + a[diff[i][1]]
					x -= 1
					i += 1
				else:
					sum = sum + b[diff[i][1]]
					y -= 1
					i += 1
			elif y > 0:
				sum = sum + b[diff[i][1]]
				y -= 1
				i += 1
			else:
				sum = sum + a[diff[i][1]]
				x -= 1
				i += 1
		return sum
if __name__ == '__main__':
	tc = int(input())
	while tc > 0:
		(n, x, y) = list(map(int, input().strip().split()))
		a = list(map(int, input().strip().split()))
		b = list(map(int, input().strip().split()))
		ans = Solution().maxTip(a, b, n, x, y)
		print(ans)
		tc -= 1


class Solution:

	def maxTip(self, a, b, n, x, y):
		(array, tips) = ([], 0)
		for i in range(0, n):
			array.append([a[i], b[i], abs(a[i] - b[i])])
		array.sort(reverse=True, key=lambda x: x[2])
		for i in range(0, n):
			if array[i][0] > array[i][1] and x != 0:
				tips += array[i][0]
				x -= 1
			elif array[i][0] < array[i][1] and y != 0:
				tips += array[i][1]
				y -= 1
			elif x == 0:
				tips += array[i][1]
			else:
				tips += array[i][0]
		return tips


class Solution:

	def maxTip(self, a, b, n, x, y):
		val = []
		for i in range(n):
			val.append([abs(a[i] - b[i]), i])
		cond1 = lambda val: val[0]
		val.sort(key=cond1, reverse=True)
		c = 0
		for i in range(n):
			if a[val[i][1]] > b[val[i][1]]:
				if x > 0:
					c += a[val[i][1]]
					x -= 1
				else:
					c += b[val[i][1]]
					y -= 1
			elif y > 0:
				c += b[val[i][1]]
				y -= 1
			else:
				c += a[val[i][1]]
				x -= 1
		return c
		return c


class Solution:

	def maxTip(self, a, b, n, x, y):
		diff = []
		for i in range(n):
			diff.append((abs(a[i] - b[i]), a[i], b[i]))
		diff = sorted(diff, key=lambda diff: diff[0], reverse=True)
		m = 0
		for val in diff:
			if val[1] > val[2] and x > 0:
				m += val[1]
				x -= 1
			elif val[1] < val[2] and y > 0:
				m += val[2]
				y -= 1
			elif y > x:
				m += val[2]
				y -= 1
			else:
				m += val[1]
				x -= 1
		return m


class Solution:

	def maxTip(self, a, b, n, x, y):
		vec1 = []
		for i in range(n):
			vec1.append([abs(a[i] - b[i]), a[i], b[i]])
		vec1.sort(reverse=True)
		ans = 0
		for vec in vec1:
			if vec[1] >= vec[2] and x > 0:
				ans += vec[1]
				x -= 1
			elif vec[1] <= vec[2] and y > 0:
				ans += vec[2]
				y -= 1
			elif x == 0 and y != 0:
				ans += vec[2]
				y -= 1
			elif x != 0 and y == 0:
				ans += vec[1]
				x -= 1
		return ans


class Solution:

	def maxTip(self, a, b, n, x, y):
		(l, m) = (0, 0)
		d = [[abs(a[i] - b[i]), i] for i in range(n)]
		d.sort(key=lambda x: x[0], reverse=True)
		for z in d:
			ind = z[1]
			if a[ind] == b[ind]:
				m += a[ind]
			elif a[ind] > b[ind] and x > 0 or y == 0:
				l += a[ind]
				x -= 1
			elif y > 0:
				l += b[ind]
				y -= 1
		return l + m