Swap Sum
Practice
4 (23 votes)
Basics of greedy algorithms
Algorithms
Greedy algorithms
Problem
43% Success 3275 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
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
\(1 \leq T \leq 10 \\ 1 \leq K \leq N \leq 10^5 \\ 0 \leq A[i], B[i] \leq 10^3\)
Submissions
Please login to view your submissions
Similar Problems
Points:20
238 votes
Tags:
ApprovedEasyGreedy AlgorithmsImplementationOpen
Points:50
54 votes
Tags:
ApprovedGreedy AlgorithmsMediumOpenTrees
Points:20
30 votes
Tags:
EasyGreedy Algorithms
Editorial