#BS0000151. Đấu giá và người không hài lòng (Angry Bids)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đấu giá và người không hài lòng (Angry Bids)
Angry Bids
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
A product has producers and consumers. Producer has an ideal price and becomes unhappy if the bid is lower than . Consumer has an ideal price and becomes unhappy if the bid is higher than .
Choose an integer bid between and to minimize the total number of unhappy people. If several bids achieve the minimum, choose the smallest such bid.
Input
- The first line contains the numbers of producers and consumers.
- The second line contains ideal prices ; it is empty if .
- The third line contains ideal prices ; it is empty if .
Output
Print two integers : the smallest optimal bid and the minimum number of unhappy people.
Subtasks
- Subtask 1 (20 points): ; for all existing values; .
- Subtask 2 (30 points): ; for all existing values; .
- Subtask 3 (50 points): ; for all existing values; .
Examples
Input
3 3
10 16 12
21 20 25
Output
16 0
Explanation
The producers' thresholds are , and the consumers' thresholds are . At , every producer sees a sufficiently high bid and every consumer sees a sufficiently low bid, so nobody is unhappy. Any smaller bid displeases the producer whose threshold is . Thus the smallest price attaining the minimum count is , and the output is 16 0.