Upload code_segments/segment_196.txt with huggingface_hub
Browse files
code_segments/segment_196.txt
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
I see satyam343. I'm shaking. Please more median problems this time. I love those. Please satyam343 we believe in you.
|
2 |
+
|
3 |
+
— satyam343's biggest fan
|
4 |
+
|
5 |
+
You are given an array $a$ of length $n$ and an integer $k$. You are also given a binary array $b$ of length $n$.
|
6 |
+
|
7 |
+
You can perform the following operation at most $k$ times:
|
8 |
+
|
9 |
+
* Select an index $i$ ($1 \leq i \leq n$) such that $b_i = 1$. Set $a_i = a_i + 1$ (i.e., increase $a_i$ by $1$).
|
10 |
+
|
11 |
+
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$.
|
12 |
+
|
13 |
+
Find the maximum score that you can achieve if you perform the operations optimally.
|
14 |
+
|
15 |
+
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$.
|
16 |
+
|
17 |
+
The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.
|
18 |
+
|
19 |
+
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.
|
20 |
+
|
21 |
+
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$.
|
22 |
+
|
23 |
+
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$.
|
24 |
+
|
25 |
+
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
|
26 |
+
|
27 |
+
For each test case, output the maximum value of score you can get on a new line.
|
28 |
+
|
29 |
+
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] = [
|