AmazonOA #294
Fortune Telling
估计困难可在线判题
n cards initially show A[i]. You may flip at most m cards, and a flipped card shows the corresponding B[i]; every card must be kept and show one side. Find the minimum possible value of the largest shown value minus the smallest shown value. You may flip fewer than m cards or none at all.
输入格式
The first line contains n m, the second line contains A, and the third line contains B. The raw only gives 1≤m≤n and a value upper bound written literally as 107, with no bound on n; this site specifies 1≤n≤200000, 1≤A[i],B[i]≤10000000, covering both typesetting interpretations, 107 and 10^7.
输出格式
Output a single integer, the answer.
样例 1
输入:
5 2
1 2 17 16 9
3 4 5 6 11
输出:
8
样例 2
输入:
2 1
1 10
5 5
输出:
4
样例 3
输入:
1 1
7
100
输出:
0
样例说明
The answers are 8, 4 and 0 respectively. In the second example, flip only the 10 to 5, leaving 1 and 5 with range 4; you cannot flip two cards to get 0.