QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 256 MB 満点: 100

#2379. 绝对值游戏

統計

Alice 和 Bob 正在玩一个游戏。Alice 有一个包含 $n$ 个整数的数组 $a$,Bob 有一个包含 $n$ 个整数的数组 $b$。在每一轮中,玩家从自己的数组中移除一个元素。玩家轮流进行操作,Alice 先手。

游戏在两个数组都只剩下一个元素时结束。设 $x$ 为 Alice 数组中剩下的最后一个元素,$y$ 为 Bob 数组中剩下的最后一个元素。Alice 希望最大化 $|x - y|$,而 Bob 希望最小化这个值。双方均采取最优策略。

求游戏的最终结果。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 1000$),表示每个数组中元素的个数。 第二行包含 $n$ 个空格分隔的整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$),表示 Alice 数组中的数字。 第三行包含 $n$ 个空格分隔的整数 $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$),表示 Bob 数组中的数字。

输出格式

输出双方均采取最优策略时 $|x - y|$ 的值。

样例

输入格式 1

4
2 14 7 14
5 10 9 22

输出格式 1

4

说明

在第一个样例中,$x = 14$ 且 $y = 10$。因此,这两个值的差为 $4$。

输入格式 2

1
14
42

输出格式 2

28

说明

在第二个样例中,数组的大小已经是 $1$。因此,$x = 14$ 且 $y = 42$。

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.