Swap Sum

4

23 votes
Basics of Greedy Algorithms, Algorithms, Greedy Algorithms
Problem

You are given two arrays, A and B of length N. In one operation, you can swap A[i] and B[i]. Find the maximum sum of A after performing at most K operations.

Input format

  • The first line contains an integer T, denoting the number of test cases.
  • The first line of each test case contains two integers, N and K.
  • The second line of each test case contains N space-separated integers, elements of array A.
  • The third line of each test case contains N space-separated integers, elements of array B.

Output format

For each test case, print the maximum sum of A after performing at most K operations in a new line.

Constraints

1T101KN1050A[i],B[i]103

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For test case 1: We can perform the operations at indexes 2, 4, and 5 (1-based indexing). A becomes [1,4,1,6,5]. Hence, the answer is 17.

For test case 2: We can perform the operations at index 1 (1-based indexing). A becomes [3,5,1]. Hence, the answer is 9.

Editor Image

?