QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 64 MB Points totaux : 90

#13565. 鞋子

Statistiques

在将大部分资金花在各种项目上之后,Nadan 决定为他的软件开发人员提供高质量的鞋子。幸运的是,Nadan 在他的地下室里找到了 $N$ 只左鞋和 $M$ 只右鞋。由于它们的来源未知,这些鞋子有各种不同的尺码。

Nadan 要求你尽可能多地将鞋子配对(显然,在配对完所有可能的鞋子后,无法再选择新的配对,即配对数应为 $\min(N, M)$)。每双鞋必须由一只左鞋和一只右鞋组成。在配对鞋子时,你应该确保“丑陋度”最小。一次配对的丑陋度定义为所有配对鞋子尺码绝对差的最大值。

输入格式

第一行包含两个正整数 $N$ 和 $M$($1 \le N, M \le 100\,000$),分别表示左鞋和右鞋的数量。

第二行包含 $N$ 个整数 $L_i$($1 \le L_i \le 10^9$),表示左鞋的尺码。

第三行包含 $M$ 个整数 $R_i$($1 \le R_i \le 10^9$),表示右鞋的尺码。

输出格式

输出所有可能的鞋子配对中,最小的丑陋度。

子任务

  • 在占总分 20% 的测试数据中,满足 $N = M$。
  • 在另外占总分 50% 的测试数据中,满足 $N, M \le 5\,000$。

样例

输入样例 1

2 3
2 3
1 2 3

输出样例 1

0

输入样例 2

4 3
2 39 41 45
39 42 46

输出样例 2

1

输入样例 3

5 5
7 6 1 2 10
9 11 6 3 12

输出样例 3

4

说明

第二个样例的解释:

Nadan 有 4 只左鞋和 3 只右鞋,最多可以配对 3 双。

一种可能的配对方式是:$39 - 46$,$41 - 42$,$45 - 39$,但由于第一双鞋,这种配对的丑陋度为 $7$。

更好的配对方式是:$39 - 39$,$41 - 42$,$45 - 46$,其丑陋度为 $1$,这是可以得到的最小丑陋度。

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.