Interview Questions/Coding/Swap Limited Array Upgrade

Swap Limited Array Upgrade

Preview mode. Log in to edit, run, submit, and save progress.

Easy

Swap Limited Array Upgrade

Two project score arrays A and B each contain n values. You may perform at most k swaps. Each swap exchanges one value from A with one value from B. After all swaps, the review score is the sum of A. For each review, compute the maximum possible final sum of A. Input Format: The first line contains t, the number of test cases. Each test case contains n and k, followed by array A and array B. Output Format: For each test case, print the maximum final sum of A.

Examples

Example 1
Input:
1
5 1
1 2 3 4 5
5 4 3 2 1
Output:
19

Explanation: One useful swap is exchanging A's 1 with B's 5, increasing A's sum from 15 to 19.

Approach hint

Start with the simplest clear approach, explain the trade-off, then move toward the cleaner answer.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp