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

#BS0000151. Đấu giá và người không hài lòng (Angry Bids)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đấ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 PP producers and CC consumers. Producer ii has an ideal price pip_i and becomes unhappy if the bid is lower than pip_i. Consumer jj has an ideal price cjc_j and becomes unhappy if the bid is higher than cjc_j.

Choose an integer bid xx between 00 and 10910^9 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 P,CP,C of producers and consumers.
  • The second line contains PP ideal prices p1,…,pPp_1,\ldots,p_P; it is empty if P=0P=0.
  • The third line contains CC ideal prices c1,…,cCc_1,\ldots,c_C; it is empty if C=0C=0.

Output

Print two integers x,kx,k: the smallest optimal bid and the minimum number of unhappy people.

Subtasks

  • Subtask 1 (20 points): 0≤P,C≤300\le P,C\le30; 1≤pi,cj≤1031\le p_i,c_j\le10^3 for all existing values; 0≤x≤1090\le x\le10^9.
  • Subtask 2 (30 points): 0≤P,C≤20000\le P,C\le2000; 1≤pi,cj≤1061\le p_i,c_j\le10^6 for all existing values; 0≤x≤1090\le x\le10^9.
  • Subtask 3 (50 points): 0≤P,C≤1040\le P,C\le10^4; 1≤pi,cj≤1081\le p_i,c_j\le10^8 for all existing values; 0≤x≤1090\le x\le10^9.

Examples

Input

3 3
10 16 12
21 20 25

Output

16 0

Explanation

The producers' thresholds are 10,16,1210,16,12, and the consumers' thresholds are 21,20,2521,20,25. At x=16x=16, 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 1616. Thus the smallest price attaining the minimum count 00 is 1616, and the output is 16 0.