QOJ.ac

QOJ

実行時間制限: 5 s メモリ制限: 1024 MB 満点: 100

#8645. 种菜很有趣 5

統計

Bitaro 多年来一直热爱园艺,他计划从今年春天开始种植一种名为“Bita-radish”的植物。

Bitaro 准备了 $2N$ 株 Bita-radish 幼苗。幼苗编号为 $1$ 到 $2N$,Bitaro 计划按此顺序进行栽培。第 $i$ 株幼苗($1 \le i \le 2N$)的大小为 $A_i$。为了让每株幼苗都能获得充足的阳光,幼苗的大小满足以下条件:

  • $A_1 \le A_2 \le \dots \le A_N \le A_{N+1}$。
  • $A_{N+1} \ge A_{N+2} \ge \dots \ge A_{2N-1} \ge A_{2N} \ge A_1$。

注意,第 $1$ 株幼苗最小,第 $N+1$ 株幼苗最大。

Bitaro 还准备了 $N$ 个红色花盆和 $N$ 个蓝色花盆,每个花盆也有一定的大小。第 $j$ 个($1 \le j \le N$)红色花盆的大小为 $B_j$,第 $k$ 个($1 \le k \le N$)蓝色花盆的大小为 $C_k$。Bitaro 在这总共 $2N$ 个花盆中各种植一株 Bita-radish 幼苗,并将花盆排成一排,使得幼苗 $1, 2, \dots, 2N$ 按此顺序排列。

考虑到外观,这 $2N$ 个花盆必须以“美观的顺序”排列。这里,“美观的顺序”是指花盆的排列方式使得存在连续的 $N$ 个相同颜色的花盆。更准确地说,当且仅当存在一个整数 $l$($1 \le l \le N+1$),使得种植了幼苗 $l, l+1, \dots, l+N-1$ 的花盆颜色全部相同时,该花盆排列被称为美观的顺序。

当大小为 $y$ 的幼苗种植在大小为 $x$ 的花盆中时,该对组合的栽培难度为绝对值 $|x-y|$。Bitaro 种植 Bita-radish 的工作量是所有 $2N$ 对花盆与幼苗组合中栽培难度的最大值。

请编写一个程序,在给定 Bita-radish 幼苗和花盆信息的情况下,求出在满足花盆排列为美观顺序的前提下,Bitaro 工作量的最小值。

输入格式

输入通过标准输入给出,格式如下:

$N$ $A_1 \ A_2 \ \dots \ A_{2N}$ $B_1 \ B_2 \ \dots \ B_N$ $C_1 \ C_2 \ \dots \ C_N$

输出格式

输出一行,包含一个整数,表示在花盆排列为美观顺序的前提下,Bitaro 工作量的最小值。

数据范围

  • $1 \le N \le 300\,000$。
  • $1 \le A_i \le 10^9$ ($1 \le i \le 2N$)。
  • $1 \le B_j \le 10^9$ ($1 \le j \le N$)。
  • $1 \le C_k \le 10^9$ ($1 \le k \le N$)。
  • $A_1 \le A_2 \le \dots \le A_N \le A_{N+1}$。
  • $A_{N+1} \ge A_{N+2} \ge \dots \ge A_{2N-1} \ge A_{2N} \ge A_1$。
  • 所有输入值均为整数。

子任务

  1. (4 分) $N \le 5$。
  2. (5 分) $N \le 10$。
  3. (21 分) $N \le 2\,000$。
  4. (37 分) 所有 $A_i$ 的值互不相同。此外,$A_N < A_{2N}$ 成立。
  5. (33 分) 无附加限制。

样例

样例输入 1

2
1 2 6 3
2 5
4 3

样例输出 1

2

说明 1

在该样例中,Bitaro 可以通过以下方式种植幼苗,从而实现 $2$ 的工作量:

  • 将幼苗 $1$ 种植在第 $1$ 个红色花盆中。该对组合的栽培难度为 $|2 - 1| = 1$。
  • 将幼苗 $2$ 种植在第 $2$ 个蓝色花盆中。该对组合的栽培难度为 $|3 - 2| = 1$。
  • 将幼苗 $3$ 种植在第 $1$ 个蓝色花盆中。该对组合的栽培难度为 $|4 - 6| = 2$。
  • 将幼苗 $4$ 种植在第 $2$ 个红色花盆中。该对组合的栽培难度为 $|5 - 3| = 2$。

种植幼苗 $2$ 和 $3$ 的花盆颜色均为蓝色,因此花盆排列为美观的顺序。 在满足花盆排列为美观顺序的前提下,无法实现小于 $2$ 的工作量。因此,输出为 $2$。

样例输入 2

9
1 2 3 4 5 6 7 8 9 18 17 16 15 14 13 12 11 10
2 7 4 1 7 6 4 10 6
6 8 9 3 7 1 9 5 4

样例输出 2

8

样例输入 3

7
13 16 18 18 21 22 22 23 23 21 19 17 15 14
14 14 20 19 22 17 25
24 15 18 25 24 19 11

样例输出 3

3

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.