#BS0000263. Mức giá cân bằng (Invisible Hand)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Mức giá cân bằng (Invisible Hand)
Invisible Hand
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
An apple market has sellers and buyers. Seller accepts a price of at least yen, whereas buyer accepts a price of at most yen. Find the smallest integer price at which willing sellers number at least as many as willing buyers.
Input
The first line contains integers .
The second line contains integers .
The third line contains integers .
Output
Print the minimum qualifying integer price .
Subtasks
- Subtask 1 (20 points): ; ().
- Subtask 2 (30 points): ; (); ; .
- Subtask 3 (50 points): ; ().
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.