#abc312c. C - Invisible Hand

C - Invisible Hand

Score : 300300 points

问题描述

在一个苹果市场中,有 NN 个卖家和 MM 个买家。

ii 个卖家可以以不少于 AiA_i 日元的价格出售一个苹果(日元是日本的货币)。

ii 个买家可以以不多于 BiB_i 日元的价格购买一个苹果。

找出满足以下条件的最小整数 XX

条件:能够以 XX 日元出售苹果的人数大于或等于能够以 XX 日元购买苹果的人数。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN sellers and MM buyers in an apple market.

The ii-th seller may sell an apple for AiA_i yen or more (yen is the currency in Japan).

The ii-th buyer may buy an apple for BiB_i yen or less.

Find the minimum integer XX that satisfies the following condition.

Condition: The number of people who may sell an apple for XX yen is greater than or equal to the number of people who may buy an apple for XX yen.

Constraints

  • 1N,M2×1051 \leq N,M \leq 2\times 10^5
  • 1Ai,Bi1091\leq A_i,B_i \leq 10^9
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN MM

A1A_1 \ldots ANA_N

B1B_1 \ldots BMB_M

Output

Print the answer.

Sample Input 1

3 4
110 90 120
100 80 120 10000

Sample Output 1

110

Two sellers, the 11-st and 22-nd, may sell an apple for 110110 yen; two buyers, the 33-rd and 44-th, may buy an apple for 110110 yen. Thus, 110110 satisfies the condition.

Since an integer less than 110110 does not satisfy the condition, this is the answer.

Sample Input 2

5 2
100000 100000 100000 100000 100000
100 200

Sample Output 2

201

Sample Input 3

3 2
100 100 100
80 120

Sample Output 3

100

update @ 2024/3/10 08:53:16