PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000263. Mức giá cân bằng (Invisible Hand)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Mức giá cân bằng (Invisible Hand)

Invisible Hand

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

An apple market has NN sellers and MM buyers. Seller ii accepts a price of at least AiA_i yen, whereas buyer jj accepts a price of at most BjB_j yen. Find the smallest integer price XX at which willing sellers number at least as many as willing buyers.

Input

The first line contains integers N,MN,M.

The second line contains NN integers A1,…,ANA_1,\ldots,A_N.

The third line contains MM integers B1,…,BMB_1,\ldots,B_M.

Output

Print the minimum qualifying integer price XX.

Subtasks

  • Subtask 1 (20 points): 1≤N,M≤201\le N,M\le20; 1≤Ai,Bj≤1001\le A_i,B_j\le100 (1≤i≤N,1≤j≤M1\le i\le N,1\le j\le M).
  • Subtask 2 (30 points): 1≤N,M≤2⋅1051\le N,M\le2\cdot10^5; 1≤Ai,Bj≤1091\le A_i,B_j\le10^9 (1≤i≤N,1≤j≤M1\le i\le N,1\le j\le M); A1=⋯=ANA_1=\cdots=A_N; B1=⋯=BMB_1=\cdots=B_M.
  • Subtask 3 (50 points): 1≤N,M≤2⋅1051\le N,M\le2\cdot10^5; 1≤Ai,Bj≤1091\le A_i,B_j\le10^9 (1≤i≤N,1≤j≤M1\le i\le N,1\le j\le M).

Examples

Input 1

3 4
110 90 120
100 80 120 10000

Output 1

110

Explanation

At 110, two sellers (90,110) and two buyers (120,10000) are willing. At 109, only one seller and two buyers are willing; lower prices cannot improve the condition.

Input 2

5 2
100000 100000 100000 100000 100000
100 200

Output 2

201

Explanation

At 200, there are zero willing sellers and one willing buyer. At 201 there are no willing buyers, so zero sellers suffice.