P18475 [CodeChef] SYMARRSWAP
提高
题目描述

Chef has two arrays A and B of the same size N.

In one operation, Chef can:
Choose an index i (1 ≤ i ≤ N) and swap the elements A_{i} and B_{i}.

Chef came up with a task to find the minimum possible value of (A_{max} - A_{min}) after performing the swap operation any (possibly zero) number of times.

Since Chef is busy, can you help him solve this task?

Note that A_{max} and A_{min} denote the maximum and minimum elements of the array A respectively.

------ Input Format ------

  • The first line of input will contain a single integer T, denoting the number of test cases.
  • Each test case consists of multiple lines of input.
  • The first line of each test case contains one integer N — the number of elements in each array.
  • The second line consists of $N space-separated integers A_{1}, A_{2},\ldots ,A_{N}$ denoting the elements of the array A.
  • The third line consists of $N space-separated integers B_{1}, B_{2}, \ldots ,B_{N}$ denoting the elements of the array B.

------ Output Format ------

For each test case, output on a new line, the minimum possible value of (A_{max} - A_{min}) in the array A after doing swap operation any number of times.

------ Constraints ------

$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 2\cdot 10^{5}$
$1 ≤ A_{i}, B_{i} ≤ 10^{9}$
- The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$.

----- Sample Input 1 ------
3
2
1 2
2 1
3
1 5 3
2 3 1
4
4 2 5 1
5 3 4 1

----- Sample Output 1 ------
0
1
3

----- explanation 1 ------
Test case $1$: Chef can make the following operations:
- Operation $1$: Choose $i=1$ and swap $A_{1}$ with $B_{1}$.

By doing the above operations, array $A$ becomes $[2, 2]$. Here $(A_{max} - A_{min}) = 0$. It can be shown that this is the minimum value possible.

Test case $2$: Chef can make the following operations:
- Operation $1$: Choose $i=1$ and swap $A_{1}$ with $B_{1}$.
- Operation $2$: Choose $i=2$ and swap $A_{2}$ with $B_{2}$.

By doing the above operations, array $A$ becomes $[2, 3, 3]$. Here $(A_{max} - A_{min}) = 1$. It can be shown that this is the minimum value possible.

Test case $3$: Chef can make the following operations:
- Operation $1$: Choose $i=2$ and swap $A_{2}$ with $B_{2}$.
- Operation $2$: Choose $i=3$ and swap $A_{3}$ with $B_{3}$.

By doing the above operations, array $A$ becomes $[4, 3, 4, 1]$. Here $(A_{max} - A_{min}) = 3$. It can be shown that this is the minimum value possible.

输入格式

见题面

输出格式

见题面

样例输入
3 2 1 2 2 1 3 1 5 3 2 3 1 4 4 2 5 1 5 3 4 1
样例输出
0 1 3