QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#14102. A系列

Statistics

有 $N + 1$ 种不同尺寸的纸张:A0, A1, A2, ..., AN,其中每种尺寸的纸张大小都是下一个尺寸的两倍。

你有 $a_0$ 张尺寸为 A0 的纸张,$a_1$ 张尺寸为 A1 的纸张,……,$a_N$ 张尺寸为 AN 的纸张。你希望获得至少 $b_0$ 张尺寸为 A0 的纸张,$b_1$ 张尺寸为 A1 的纸张,……,$b_N$ 张尺寸为 AN 的纸张。在任何时候,你都可以将一张纸对折并裁剪,从而得到两张尺寸更小一号的纸(例如,A4 $\to$ A5 $\times$ 2)。

要获得所需的纸张,最少需要进行多少次裁剪?

输入格式

第一行包含一个整数 $N$ ($1 \le N \le 2 \cdot 10^5$)。

第二行包含 $N + 1$ 个整数 $a_0, a_1, \dots, a_N$ ($0 \le a_i \le 10^9$)。

第三行包含 $N + 1$ 个整数 $b_0, b_1, \dots, b_N$ ($0 \le b_i \le 10^9$)。

输出格式

输出一个整数——获得所需纸张所需的最少裁剪次数;如果无法获得,则输出 $-1$。

样例

输入样例 1

1
10 0
0 19

输出样例 1

10

输入样例 2

1
10 0
0 21

输出样例 2

-1

输入样例 3

3
2021 11 21 10
10 21 11 2021

输出样例 3

1758

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.