QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 2048 MB Total points: 100

#10337. Charming Meals

统计

捷克菜肴包含 $n$ 道开胃菜和 $n$ 道主菜。第 $i$ 道开胃菜的辣度为 $a_i$,第 $i$ 道主菜的辣度为 $b_i$。

一份典型的捷克餐包含恰好一道开胃菜和一道主菜。你需要将 $n$ 道开胃菜和 $n$ 道主菜配对成 $n$ 份餐点,使得每道开胃菜和每道主菜都恰好被包含在其中一份餐点中。

为了给用餐者带来惊喜,你希望同一份餐点中两部分的辣度尽可能不同。一份餐点的“魅力值”定义为开胃菜辣度与主菜辣度之差的绝对值。因此,由辣度为 $x$ 的开胃菜和辣度为 $y$ 的主菜组成的餐点,其魅力值为 $|x - y|$。

你希望最大化这 $n$ 份餐点中魅力值的最小值。请问你能达到的最小魅力值的最大可能值是多少?

输入格式

每个测试点包含多个测试用例。第一行包含一个整数 $t$ ($1 \le t \le 1\,000$),表示测试用例的数量。接下来是 $t$ 个测试用例的描述。

每个测试用例的第一行包含一个整数 $n$ ($1 \le n \le 5\,000$),表示开胃菜和主菜的数量。

每个测试用例的第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^9$),表示 $n$ 道开胃菜的辣度。

每个测试用例的第三行包含 $n$ 个整数 $b_1, b_2, \dots, b_n$ ($0 \le b_i \le 10^9$),表示 $n$ 道主菜的辣度。

保证所有测试用例中 $n^2$ 的总和不超过 $25 \cdot 10^6$。

输出格式

对于每个测试用例,输出你能达到的最小魅力值的最大可能值。

样例

输入 1

4
3
0 0 0
1000000000 1000000000 1000000000
5
1 2 3 4 5
1 2 3 4 5
6
0 0 0 100 100 100
100 100 100 0 0 0
7
14 25 62 74 86 95 12
51 62 71 72 92 20 84

输出 1

1000000000
2
100
30

说明

在第一个测试用例中,无论你如何配对开胃菜和主菜,每份餐点都将包含一个辣度为 0 的开胃菜和一个辣度为 1000000000 的主菜,因此每份餐点的魅力值均为 1000000000。

在第二个测试用例中,一种最优的配对方式是:(1, 5), (2, 4), (3, 1), (4, 2), (5, 3)。对应的餐点魅力值为:4, 2, 2, 2, 2。所得的最小魅力值为 2。

在第三个测试用例中,最大化最小魅力值的一种方法是将三道辣度为 0 的开胃菜与三道辣度为 100 的主菜配对,并将三道辣度为 100 的开胃菜与三道辣度为 0 的主菜配对。这样,每份餐点的魅力值都恰好为 100。

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.