#C8501. Maximum Sum of Minimum Pairs
Maximum Sum of Minimum Pairs
Maximum Sum of Minimum Pairs
You are given two arrays A and B, each consisting of n integers. Your task is to maximize the sum of the minimums of paired elements when you are allowed to permute both arrays arbitrarily. Formally, you need to maximize the sum
\( \sum_{i=1}^{n} \min(A_i, B_i) \)
It can be proven that sorting both arrays in non-decreasing order and pairing the corresponding elements yields the maximum sum.
Example: For A = [1, 3, 2] and B = [6, 4, 5], when both arrays are sorted we get A = [1, 2, 3] and B = [4, 5, 6], and the sum is min(1,4) + min(2,5) + min(3,6) = 1 + 2 + 3 = 6.
inputFormat
The first line contains an integer T representing the number of test cases. Each test case consists of three lines:
- The first line contains an integer n, the number of elements in each array.
- The second line contains n space-separated integers representing array A.
- The third line contains n space-separated integers representing array B.
outputFormat
For each test case, output a single line containing the maximum sum of minimums of paired elements.
## sample2
3
1 3 2
6 4 5
4
8 7 9 6
1 2 3 4
6
10
</p>