Напомена: ово је незванична копија задатака. Као таква, не гарантује се да ће овај сајт бити одржаван, и немојте се изненадити ако са њега задаци одједном нестану.
The vote for the cutoff to qualify to the state athletics competition is under way. Each committee member will write a number on a piece of paper and cast their vote by putting it into the vote box. The cutoff will then be chosen as the median of all votes in the box.
When “Chad” Markos, the most popular member of the committee, showed up for the vote, he noticed that nobody was paying attention to the vote box. He decided to wait until everyone else casts their vote, and then peek into the box, find out what the votes are and then insert as many extra votes as needed (but no more than necessary) to make the cutoff match his desired result \(B_i\).
We will consider \(Q\) scenarios, where Markos’ preferred result in scenario \(i\) is \(B_i\). For each scenario, you should help Markos to pick the lowest number of votes he can add the outcome \(B_i\). There are already \(N\) votes in the box, given in the array \(A_1, A_2, \dots, A_N\).
The first line of the standard input contains two integers \(N\) and \(Q\): the number of votes already in the box and the number of scenarios you should consider.
The second line contains \(N\) integers: \(A_1, A_2, \dots, A_N\), the votes already in the box.
The third line contains \(Q\) integers: \(B_1, B_2, \dots, B_Q\), where \(B_i\) is Markos’ preferred outcome in the \(i\)-th scenario.
Your program should output \(Q\) lines to the standard output, each containing one integer, where the \(i\)-th integer is the smallest number of extra votes Markos can cast to ensure the outcome is \(B_i\).
5 3
1 3 5 7 9
5 7 10
0
1
5
In the first scenario, the median is already 5, so Markos doesn’t have to do anything and the answer is 0. In the second scenario, Markos can cast a single vote of 8 to increase the median to 7, so the answer is 1. Finally, in the third scenario, Markos has to cast at least five votes, and write 10 on each.
Testcases are split into four non-overlapping groups:
For an array \(A_1, A_2, \dots, A_N\) with \(N\) elements, we define the median as the value that would be in the middle if the array was sorted. More formally, let \(A'\) be the result of sorting \(A\). The median of \(A\) is then defined as \(A'_{\lfloor\dfrac{N}{2}\rfloor + 1}\). For example, if \(A = [5, 7, 3, 6]\), the sorted array \(A'\) would be \([3, 5, 6, 7]\), and the median would be \(6\).