QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 1024 MB Puntuación total: 100

#1959. 约翰的礼物

Estadísticas

每天早晨,店主 John 都会收到 $n$ 个价值各不相同的商品和 $n$ 个价格各不相同的价格标签。为了尽可能多地销售商品,John 会在商品和价格标签之间进行匹配,以最小化两者之间的最大差值(简称“最大差值”),其中不同的商品必须匹配不同的价格标签。例如,如果 John 有两个价值分别为 $10$ 和 $30$ 的商品,以及两个价格分别为 $10$ 和 $20$ 的标签,那么通过匹配 $(10, 10)$ 和 $(30, 20)$,最大差值可以最小化为 $10$。这个最小的最大差值被称为匹配得分。

今天,John 的朋友 Jane 要举办生日派对,John 决定从他的商品中挑选一件作为生日礼物。在选择商品时,他不希望损失太多的利润,因此他想选择一件商品,使得移除该商品后,剩余的 $n-1$ 个商品与原始的 $n$ 个价格标签之间的匹配得分最小。顺便提一下,在匹配 $n-1$ 个商品时,John 会留出一个价格标签不进行匹配,以完成合理的匹配。

例如,John 有两个商品 $G_1$ 和 $G_2$,其价值分别为 $10$ 和 $30$,以及两个价格标签 $10$ 和 $20$。如果他选择 $G_1$ 作为礼物,那么 $G_2$ 的可能价格为 $10$ 或 $20$。当 $G_2$ 定价为 $20$ 时,匹配得分为 $10$。另一方面,如果他选择 $G_2$ 作为礼物,那么当 $G_1$ 定价为 $10$ 时,匹配得分为 $0$。因此,为了获得最小的匹配得分,John 会选择 $G_2$ 作为礼物。换句话说,在 $n$ 个商品中,John 可以挑选任意一件商品作为礼物,这定义了剩余的 $n-1$ 个商品与原始的 $n$ 个价格标签之间的一种新的匹配得分。在 $n$ 种可能的礼物选择中,John 希望找到一件商品,其移除后产生的匹配得分最小。

给定 $n$ 个商品价值和 $n$ 个价格标签,编写一个程序,输出 John 应该挑选的礼物商品的价值,以使剩余的 $n-1$ 个商品与 $n$ 个价格标签之间的匹配得分最小。如果有两个或更多候选商品,请输出候选商品中价值最小的那一个。

输入格式

程序从标准输入读取数据。输入的第一行包含一个整数 $n$ ($2 \le n \le 10^6$),表示商品的数量和价格标签的数量。第二行包含 $n$ 个正且不同的整数,表示 $n$ 个商品的价值。第三行包含 $n$ 个正且不同的整数,表示 $n$ 个价格标签。商品价值和标签价格均不超过 $10^9$。

输出格式

程序写入标准输出。仅输出一行。该行应包含 John 为 Jane 的生日礼物挑选的商品价值,使得移除该商品后,剩余的 $n-1$ 个商品产生的匹配得分最小。如果有多个候选商品,请输出候选商品中价值最小的一个。

样例

样例输入 1

2
10 30
10 20

样例输出 1

30

样例输入 2

3
20 30 40
30 20 10

样例输出 2

40

样例输入 3

4
24 68 51 10
20 40 50 30

样例输出 3

68

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.