AtCoder Beginner Contest 254
Ex
Multiply or Divide by 2
AtCoder
⌀ 2499
原题
←G →
翻译中…

Problem Statement

翻译中…

You are given multisets with $N$ non-negative integers each: $A=\{ a_1,\ldots,a_N \}$ and $B=\{ b_1,\ldots,b_N \}$. You can perform the operations below any number of times in any order.

翻译中…
  • Choose a non-negative integer $x$ in $A$. Delete one instance of $x$ from $A$ and add one instance of $2x$ instead.
  • Choose a non-negative integer $x$ in $A$. Delete one instance of $x$ from $A$ and add one instance of $\left\lfloor \frac{x}{2} \right\rfloor$ instead. ($\lfloor x \rfloor$ is the greatest integer not exceeding $x$.)
翻译中…

Your objective is to make $A$ and $B$ equal (as multisets). Determine whether it is achievable, and find the minimum number of operations needed to achieve it if it is achievable.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 10^5$
  • $0 \leq a_1 \leq \ldots \leq a_N \leq 10^9$
  • $0 \leq b_1 \leq \ldots \leq b_N \leq 10^9$
  • All values in input are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
a_1 \ldots a_N
b_1 \ldots b_N

翻译中…

Output

翻译中…

If the objective is achievable, print the minimum number of operations needed to achieve it; otherwise, print -1.

翻译中…

样例

Input #1
3
3 4 5
2 4 6
Output #1
2
You can achieve the objective in two operations as follows. - Choose $x=3$ to delete one instance of $x\, (=3)$ from $A$ and add one instance of $2x\, (=6)$ instead. Now we have $A=\{4,5,6\}$. - Choose $x=5$ to delete one instance of $x\, (=5)$ from $A$ and add one instance of $\left\lfloor \frac{x}{2} \right\rfloor \, (=2)$ instead. Now we have $A=\{2,4,6\}$.
Input #2
1
0
1
Output #2
-1
You cannot turn $\{ 0 \}$ into $\{ 1 \}$.
题目信息
题号
abc254_h
时间限制
2.5 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。