| Codeforces Round 1111 (Div. 2) |
|---|
| Finished |
You are given two arrays $$$a$$$ and $$$b$$$ of length $$$n$$$, consisting only of $$$0$$$ and $$$1$$$.
You may perform the following operation on $$$a$$$ any number of times:
Find the minimum number of operations needed to transform $$$a$$$ into $$$b$$$, or determine that it is impossible.
$$$^{\text{∗}}$$$A sequence $$$c$$$ is a subsequence of a sequence $$$d$$$ if $$$c$$$ can be obtained from $$$d$$$ by the deletion of several (possibly, zero or all) elements from arbitrary positions.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the arrays $$$a$$$ and $$$b$$$.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$a_i \in \{0, 1\}$$$) — array $$$a$$$.
The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$b_i \in \{0, 1\}$$$) — array $$$b$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output a single integer — the minimum number of operations needed to transform $$$a$$$ into $$$b$$$, or $$$-1$$$ if it is impossible.
510021 00 131 1 10 0 041 0 1 00 1 0 151 0 1 0 11 1 1 1 1
0112-1
In the first example, $$$a = b$$$, so no operations are needed. Therefore, the answer is $$$0$$$.
In the second example, we can perform an operation with the subsequence $$$[a_1, a_2]$$$. The sum of its elements is $$$1 + 0 = 1$$$, which is odd. This operation transforms $$$a$$$ as follows: $$$[\color{red}{1, 0}] \rightarrow [\color{red}{0, 1}]$$$. The resulting array equals $$$b$$$, so the answer is $$$1$$$.
| Name |
|---|


