全部加一或单独取反AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)You are given length-$N$ integer sequences: $A=(A_1,A_2,\ldots,A_N)$ and $B=(B_1,B_2,\ldots,B_N)$.
给定两个长度为 $N$ 的整数序列:$A=(A_1,A_2,\ldots,A_N)$ 和 $B=(B_1,B_2,\ldots,B_N)$。AI (CI翻译)
You can perform the following two types of operations any number of times in any order.
你可以按照任意顺序执行以下两种操作任意次:AI (CI翻译)
- Add
$1$to every element of$A$. - Choose an integer
$i$satisfying$1\leq i\leq N$, and replace$A_i$with$-A_i$.
- 将
$A$中的每个元素都加上$1$。 - 选择一个满足
$1\leq i\leq N$的整数$i$,将$A_i$替换为$-A_i$。
Determine whether it is possible to make $A$ and $B$ equal as multisets. If it is possible, also find the minimum number of operations required. Here, $A$ and $B$ are equal as multisets when, for every integer, the number of its occurrences in $A$ equals the number of its occurrences in $B$.
判断是否可以使 $A$ 和 $B$ 作为多重集合相等。如果可以,还请找出所需的最少操作次数。这里,当对于任意整数,该整数在 $A$ 中出现的次数都与其在 $B$ 中出现的次数相等时,称 $A$ 和 $B$ 作为多重集合相等。AI (CI翻译)
You are given $T$ test cases; find the answer for each of them.
给定 $T$ 个测试用例,请分别求出每个测试用例的答案。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$1\leq T\leq 10^4$$1\leq N\leq 100$$-10^9\leq A_i,B_i\leq 10^9$$(1 \leq i \leq N)$- The sum of
$N^3$over all test cases in a single input is at most$10^6$. - All input values are integers.
$1\leq T\leq 10^4$$1\leq N\leq 100$$-10^9\leq A_i,B_i\leq 10^9$$(1 \leq i\leq N)$- 单个输入中所有测试用例的
$N^3$之和不超过$10^6$。 - 所有输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入按以下格式给出:AI (CI翻译)
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_TAI (CI翻译)
Each test case is given in the following format:
每个测试用例按以下格式给出:AI (CI翻译)
N
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_N
N
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_NAI (CI翻译)
Output
输出格式
AI (CI翻译)Output $T$ lines. The $i$-th line should contain -1 if it is impossible to make $A$ and $B$ equal as multisets in the $i$-th test case, and otherwise the minimum number of operations required.
输出 $T$ 行。第 $i$ 行中,如果无法在第 $i$ 个测试用例中使 $A$ 和 $B$ 作为多重集合相等,则输出 -1;否则输出所需的最少操作次数。AI (CI翻译)
样例
8
4
-3 -1 0 2
-2 1 2 3
2
0 0
0 1
1
0
0
1
0
3
1
3
1
2
1 3
-3 1
3
-1 -1 -1
1 1 1
6
-4 -2 -2 0 1 3
-3 -1 0 2 2 4
2
-1
0
3
4
1
2
5
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。