1201C.md (1670B)
1 Source: https://codeforces.com/problemset/problem/1201/C 2 3 C. Maximum Median 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 22 23 * Choose one of the elements of the array (for example $a_i$) and increase it by $1$ (that is, replace it with $a_i + 1$). 24 25 You want to make the median of the array the largest possible using at most $k$ operations. 26 27 The median of the odd-sized array is the middle element after the array is sorted in non-decreasing order. For example, the median of the array $[1, 5, 2, 3, 5]$ is $3$. 28 29 Input 30 31 The first line contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $n$ is odd, $1 \le k \le 10^9$) — the number of elements in the array and the largest number of operations you can make. 32 33 The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$). 34 35 Output 36 37 Print a single integer — the maximum possible median after the operations. 38 39 Examples 40 41 Input 42 43 ``` 44 3 2 45 1 3 5 46 ``` 47 48 Output 49 50 ``` 51 5 52 ``` 53 54 Input 55 56 ``` 57 5 5 58 1 2 1 1 1 59 ``` 60 61 Output 62 63 ``` 64 3 65 ``` 66 67 Input 68 69 ``` 70 7 7 71 4 1 2 4 3 4 4 72 ``` 73 74 Output 75 76 ``` 77 5 78 ``` 79 80 Note 81 82 In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$. 83 84 In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$. 85 86 In the third example, you can make four operations: increase first, fourth, sixth, seventh element. This way the array will be $[5, 1, 2, 5, 3, 5, 5]$ and the median will be $5$.