P14782 [CodeChef] REMONE
提高-
题目描述

Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.

You are given both arrays A and B. You have to identify the value of X chosen by Bob. If there are multiple possible values of X, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of X.

Note: Since the input is large, prefer using fast input methods.

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

  • The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • Each test case contains 3 lines of input.
  • The first line contains an integer N - the length of array A.
  • The second line contains $N space-separated integers A_{1}, A_{2}, \dots, A_{N},$ denoting the array A.
  • The third line contains $N - 1 space-separated integers B_{1}, B_{2}, \dots, B_{N-1},$ denoting the array B.

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

For each test case, output the value of X chosen by Bob. In case there are multiple possible values of X, print the smallest of them.

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

$1 ≤ T ≤ 7$
$2 ≤ N ≤ 10^{5}$
$1 ≤ A_{i} ≤ 10^{9}$
$1 ≤ B_{i} ≤ 2 \cdot 10^{9}$
$A_{1}, A_{2}, \dots, A_{N}$ are pairwise distinct.
$B_{1}, B_{2}, \dots, B_{N-1}$ are pairwise distinct.
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.

----- Sample Input 1 ------
3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3
----- Sample Output 1 ------
7
2
1
----- explanation 1 ------
Test case $1$: Bob takes the elements $\{1, 4, 8\}$ and adds $7$ to them to obtain a new sequence $\{8, 11, 15\}$. There is no other value of $X$ that can be added to the elements of $A$ to get $B$.

Test case $3$: There is only one option with Bob to consider, i.e. to take element $\{2\}$ and add $1$ to it to get array $B$. If he takes element $\{4\}$, he will have to add $-1$ which is not allowed.

输入格式

见题面

输出格式

见题面

样例输入
3 4 1 4 3 8 15 8 11 2 4 8 10 2 2 4 3
样例输出
7 2 1