Universal Cup Judging System

Universal Cup

时间限制: 1 s 内存限制: 256 MB 总分: 100
统计

加性增/乘性减(AIMD)算法是一种反馈控制算法,最广为人知的是其在 TCP 拥塞控制中的应用。AIMD 结合了在没有拥塞时拥塞窗口的线性增长,以及在检测到拥塞时拥塞窗口的指数级减少。多个使用 AIMD 拥塞控制的流最终会收敛到对共享链路的平等使用。(摘自维基百科)

给定两个包含 $n$ 个整数的数组:$a$ 和 $b$。你可以对数组 $a$ 执行操作。在一次操作中,你可以让所有的 $a_i$ 变为 $a_i + 1$(对于所有 $1 \le i \le n$),或者让所有的 $a_i$ 变为 $\lfloor \frac{a_i}{2} \rfloor$(对于所有 $1 \le i \le n$)。

求将 $a$ 转换为 $b$ 所需的最少操作次数,如果无法转换,则输出 $-1$。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 10^6$)。 第二行包含整数数组 $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^9$)。 第三行包含整数数组 $b_1, b_2, \dots, b_n$ ($0 \le b_i \le 10^9$)。

输出格式

输出所需的最少操作次数,如果无法将 $a$ 转换为 $b$,则输出 $-1$。

样例

样例输入 1

5
1 2 3 4 5
6 6 6 6 7

样例输出 1

9

样例输入 2

3
2 3 4
1 2 3

样例输出 2

-1

样例输入 3

2
65536 65537
1 2

样例输出 3

32

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.