QOJ.ac

QOJ

時間限制: 4 s 記憶體限制: 256 MB 總分: 100

#10612. 楼梯

统计

Bajtocorp 的总部位于一座 $n$ 层高的摩天大楼中。由于预算有限,大楼内没有电梯。因此,员工只能通过楼梯在楼层间移动。根据安全规定,在单位时间内,连接第 $i$ 层和第 $i+1$ 层的楼梯最多只能通过一人(无论是从第 $i$ 层上到第 $i+1$ 层,还是从第 $i+1$ 层下到第 $i$ 层)。特别地,在同一单位时间内,不能同时有人从第 $i$ 层上到第 $i+1$ 层,又有人从第 $i+1$ 层下到第 $i$ 层。不过,在同一单位时间内,可以同时使用连接不同相邻楼层的楼梯。

Bajtazar 总裁计算出,目前第 $i$ 层有 $a_i$ 名员工。他希望最终每层的员工人数变为 $b_i$。他不关心具体的某位员工最终位于哪一层,只要每层的员工总数符合要求即可。你的任务是计算出最少需要多少个单位时间,才能使每层的员工人数达到 Bajtazar 预期的目标。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 10^6$),表示大楼的层数。 第二行包含 $n$ 个整数,表示初始状态,其中第 $i$ 个数为 $a_i$ ($0 \le a_i \le 10^9$)。 第三行包含 $n$ 个整数,表示目标状态,其中第 $i$ 个数为 $b_i$ ($0 \le b_i \le 10^9$)。 你可以假设所有 $a_i$ 的总和等于所有 $b_i$ 的总和。

输出格式

输出从初始状态转换到目标状态所需的最少单位时间。

样例

样例输入 1

3
1 0 1
0 2 0

样例输出 1

1

说明

样例测试:测试 0 为上述样例。此外: 测试 1:$n = 1000$;若 $i \pmod{10} = 0$,则 $a_i = b_{n+1-i} = i/10$,否则 $a_i = b_{n+1-i} = 0$;答案为 2558; 测试 2:$n = 1000$;$a_i = b_{n+1-i} = 10 \cdot i$;答案为 2 500 000; 测试 3:$n = 1\,000\,000$;$a_i = i \pmod 2$,$b_i = 1 - a_i$;答案为 1; 测试 4:$n = 1\,000\,000$;若 $i \le 500\,000$,则 $a_i = 10^6$ 且 $b_i = 0$,否则 $a_i = 0$ 且 $b_i = 10^6$;答案为 $5 \cdot 10^{11}$。

子任务

设 $S$ 为所有 $a_i$ 的总和(等于所有 $b_i$ 的总和)。测试集分为以下子任务。每个子任务包含一组或多组测试数据。

Podzadanie Dodatkowe ograniczenia Punkty
1 $n \le 10; S \le 100$ 7
2 $n \le 1000; S \le 20\,000$ 10
3 $n \le 1000$ 31
4 $n \le 200\,000$ 33
5 Brak 19

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.