Codeforces Round 965 (Div. 2) |
---|
Finished |
You are given an array $$$a$$$ of length $$$n$$$ and an integer $$$k$$$. You are also given a binary array $$$b$$$ of length $$$n$$$.
You can perform the following operation at most $$$k$$$ times:
Your score is defined to be $$$\max\limits_{i = 1}^{n} \left( a_i + \operatorname{median}(c_i) \right)$$$, where $$$c_i$$$ denotes the array of length $$$n-1$$$ that you get by deleting $$$a_i$$$ from $$$a$$$. In other words, your score is the maximum value of $$$a_i + \operatorname{median}(c_i)$$$ over all $$$i$$$ from $$$1$$$ to $$$n$$$.
Find the maximum score that you can achieve if you perform the operations optimally.
For an arbitrary array $$$p$$$, $$$\operatorname{median}(p)$$$ is defined as the $$$\left\lfloor \frac{|p|+1}{2} \right\rfloor$$$-th smallest element of $$$p$$$. For example, $$$\operatorname{median} \left( [3,2,1,3] \right) = 2$$$ and $$$\operatorname{median} \left( [6,2,4,5,1] \right) = 4$$$.
The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases.
Each test case begins with two integers $$$n$$$ and $$$k$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$, $$$0 \leq k \leq 10^9$$$) — the length of the $$$a$$$ and the number of operations you can perform.
The following line contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — denoting the array $$$a$$$.
The following line contains $$$n$$$ space separated integers $$$b_1, b_2, \ldots, b_n$$$ ($$$b_i$$$ is $$$0$$$ or $$$1$$$) — denoting the array $$$b$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output the maximum value of score you can get on a new line.
82 103 31 13 103 3 30 0 04 42 1 5 10 1 0 15 47 5 2 5 40 0 1 0 15 15 15 15 2 111 0 0 1 15 210 11 4 10 151 1 0 1 04 41 1 2 51 1 0 02 10000000001000000000 10000000001 1
16 6 8 13 21 26 8 3000000000
For the first test case, it is optimal to perform $$$5$$$ operations on both elements so $$$a = [8,8]$$$. So, the maximum score we can achieve is $$$\max(8 + \operatorname{median}[8], 8 + \operatorname{median}[8]) = 16$$$, as $$$c_1 = [a_2] = [8]$$$. It can be proven that you cannot get a better score.
For the second test case, you are not able to perform operations on any elements, so $$$a$$$ remains $$$[3,3,3]$$$. So, the maximum score we can achieve is $$$3 + \operatorname{median}[3, 3] = 6$$$, as $$$c_1 = [a_2, a_3] = [3, 3]$$$. It can be proven that you cannot get a better score.
Name |
---|