Question
Price Sorting Puzzle
In a village market, Leo is sorting a list of N fruit prices into three categories: low-priced, mid-priced, and high-priced fruits. He decides to select the K lowest prices as low-priced fruits and the K highest prices as high-priced fruits. Any remaining prices will fall into the mid-priced category. However, there’s a twist - some prices might end up counted in both the low-priced and high-priced categories.
Given the list of fruit prices and the value of K, can you help Leo determine how many prices fall only in the mid-priced category?
Input
First line of the input contains two space-separated integers N and K.
Next line of the input contains N space-separated integers.
Constraints
1 ≤ K ≤ N ≤ 105
1 ≤ a[i] ≤ 109
Try solving it without using extra space.
Next line of the input contains N space-separated integers.
Constraints
1 ≤ K ≤ N ≤ 105
1 ≤ a[i] ≤ 109
Try solving it without using extra space.
Output
A single integer denoting the count of Medium numbers.
Example
Sample Input
9 2
5 1 7 2 6 1 8 6 3
Sample Output
3
Explanation
Lower numbers => {1, 2} => 2 smallest numbers
higher numbers => {8, 7} => 2 greatest numbers
medium numbers => {3, 5, 6}
6 occurs twice in the list but will be counted only once.
9 2
5 1 7 2 6 1 8 6 3
Sample Output
3
Explanation
Lower numbers => {1, 2} => 2 smallest numbers
higher numbers => {8, 7} => 2 greatest numbers
medium numbers => {3, 5, 6}
6 occurs twice in the list but will be counted only once.