题目描述
Chef is given two arrays A and B of length N each.
In one operation Chef can choose one element of A and one element of B and increase them by 1.
More formally:
Chef can pick two integers i, j (1≤ i, j ≤ N) and increment A_{i} and B_{j} by 1.
Determine the minimum number of operations required to make A and B equal.
Output -1 if it is not possible to make A and B equal.
------ 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 a single integer N - denoting the length of arrays A and B.
- The second line of each test case contains $N space separated integers A_{1}, A_{2}, A_{3}, \dots A_{N} -$ denoting the array A.
- The third line of each test case contains $N space separated integers B_{1}, B_{2}, B_{3}, \dots B_{N} -$ denoting the array B.
------ Output Format ------
For each test case, output the minimum number of operations to make A and B equal or -1 if they cannot be made equal.
------ Constraints ------
$1 ≤ T ≤ 2 \cdot 10^{4}$
$2 ≤ N ≤ 10^{5}$
$1 ≤ A_{i}, B_{i} ≤ 10^{9}$
- Sum of $N$ over all test cases do not exceed $10^{5}$.
----- Sample Input 1 ------
3
2
1 2
2 1
3
1 1 2
2 2 1
3
4 6 8
5 7 6
----- Sample Output 1 ------
1
-1
2
----- explanation 1 ------
Test case $1$: We can choose $i = 1$ and $j = 2$ and increment $A_{i}$ and $B_{j}$ by $1$. Thus, both arrays become $[2, 2]$ and are equal. We require only $1$ operation to make these arrays equal. It can be proven that the arrays cannot be made equal in less than one operation.
Test case $2$: Both the arrays cannot be made equal using any number of operations.
Test case $3$: We perform $2$ operations as follows:
- Choose $i = 1, j = 3$: The arrays become $A = [5, 6, 8]$ and $B = [5, 7, 7]$.
- Choose $i = 2, j = 3$: The arrays become $A = [5, 7, 8]$ and $B = [5, 7, 8]$.
Thus, both arrays can be made equal using $2$ operations.
输入格式
见题面
输出格式
见题面