description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = sorted(map(int, input().split()))
c = 1
i = n // 2
s = a[i]
while i < n - 1 and k > 0:
t = min(a[i + 1] - s, k // c)
s += t
k -= t * c
c += 1
i += 1
if k > 0:
s += k // c
print(s)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
l.sort()
med = l[n // 2]
for i in range(n // 2 + 1, n):
diff = l[i] - l[i - 1]
if diff > 0:
if k >= diff * (i - n // 2):
med = l[i]
k -= diff * (i - n // 2)
else:
if k >= i - n // 2:
med = med + k // (i - n // 2)
k -= k // (i - n // 2) * (i - n // 2)
break
num = n // 2 + 1
if k < num:
print(med)
else:
print(med + k // num)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
a, b = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
index = a // 2 + 1
count = 1
while b > 0:
if index == a:
l[a // 2] += b // (a // 2 + 1)
break
diff = l[index] - l[a // 2]
if count * diff <= b:
b -= count * diff
count += 1
index += 1
l[a // 2] += diff
else:
l[a // 2] += b // count
break
print(l[a // 2])
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
a.sort()
mid = (n - 1) // 2
while k > 0:
i = mid
while i < n and a[i] == a[mid]:
i += 1
res = i - mid
if res == 0:
k -= a[mid + 1]
if k >= 0:
a[mid] = a[mid + 1]
else:
a[mid] += k
break
elif k >= res and i == n:
val = k // res
a[mid] += val
break
elif k >= res:
val = a[i] - a[mid]
mo = k // res
if mo <= val:
a[mid] += mo
break
else:
for j in range(mid, i):
a[j] += val
k -= val * res
else:
break
print(a[mid])
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
if n == 1:
print(a[0] + k)
else:
a.sort()
x = n // 2
if a[x] + k <= a[x + 1]:
print(a[x] + k)
else:
nextelem = x + 1
countelem = 1
incer = 0
prev = a[x]
while nextelem < n:
diff = a[nextelem] - prev
if k >= countelem * diff:
k = k - countelem * diff
incer = incer + diff
prev = a[nextelem]
nextelem = nextelem + 1
countelem = countelem + 1
else:
break
if k > 0:
incer = incer + k // countelem
print(a[x] + incer)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mid = int(n / 2)
up = mid + 1
while k > 0:
if up >= n:
k -= n - mid
a[mid] += 1
elif a[up] == a[mid]:
up += 1
else:
k -= up - mid
a[mid] += 1
if k == 0:
print(a[mid])
else:
print(a[mid] - 1)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
import sys
input = sys.stdin.readline
def judge(x):
cnt = 0
for i in range(n // 2, n):
cnt += max(x - a[i], 0)
return cnt <= k
def binary_search():
left, right = 1, 10**20
while left <= right:
mid = (left + right) // 2
if judge(mid):
left = mid + 1
else:
right = mid - 1
return right
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
print(binary_search())
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = list(sorted(map(int, input().split())))
count = a[n // 2]
num = 1
for i in range(n // 2 + 1, n):
if (a[i] - count) * num <= k:
k -= (a[i] - count) * num
count = a[i]
else:
break
num += 1
print(count + k // num)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
arr = list(map(int, input().split()))
if n == 1:
print(arr[0] + k)
exit(0)
arr.sort()
i = (n - 1) // 2
m = arr[i]
cnt = 1
i += 1
while i < n:
nxt = arr[i]
if k < (nxt - m) * cnt:
print(m + k // cnt)
exit(0)
k -= (nxt - m) * cnt
m = nxt
cnt += 1
i += 1
if k >= 0:
print(m + k // cnt)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = [int(x) for x in input().split()]
a = sorted([int(x) for x in input().split()])
med = len(a) // 2
look = med
extra = 0
idiff = 0
last = a[med]
while look < len(a) - 1:
look += 1
idiff += 1
diff = a[look] - last
last = a[look]
chunk = idiff * diff
if chunk <= k:
k -= chunk
extra += diff
else:
extra += k // idiff
k = 0
if k > 0:
extra += k // (idiff + 1)
print(a[med] + extra)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
def int_multiple():
return [int(c) for c in input().split()]
def int_single():
return int(input())
def str_multiple():
return [c for c in input().split()]
def str_single():
return input()
n, k = int_multiple()
l = int_multiple()
l = sorted(l)
mid = int(n / 2)
l = l[mid:]
acc = []
r = 0
for i in range(len(l)):
r += l[i]
acc.append(r)
ans = 0
for i in reversed(range(len(l))):
need = l[i] * (i + 1)
hand = acc[i] + k
if hand >= need:
left = hand - need
additional = int(left / (i + 1))
ans = l[i] + additional
break
print(ans)
|
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
def median(l, n, k):
l = l[n // 2 :]
n = n // 2 + 1
diffs = []
for i in range(n - 1):
diffs.append((l[i + 1] - l[i]) * (i + 1))
diff = sum(diffs)
if diff <= k:
k -= diff
last = l[-1] + k // n
k %= n
return last
else:
t = 0
val = l[0]
while t < n - 1:
if diffs[t] <= k:
val += diffs[t] // (t + 1)
k -= diffs[t]
t += 1
else:
val += k // (t + 1)
break
if k == 0:
break
return val
n, k = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
print(median(l, n, k))
|
FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
attributes = [int(x) for x in input().split()]
ints = [int(x) for x in input().split()]
ints.sort()
length = len(ints)
n = len(ints) // 2 - 1
r = n
cont = True
while cont == True:
r += 1
t = ints[r]
z = r + 1
while z < length and ints[z] == ints[r]:
z += 1
if z != length:
if (ints[z] - ints[r]) * (z - n - 1) <= attributes[1]:
attributes[1] -= (ints[z] - ints[r]) * (z - n - 1)
r = z - 1
else:
print(ints[r] + attributes[1] // (z - n - 1))
cont = False
else:
print(ints[z - 1] + attributes[1] // (z - n - 1))
cont = False
|
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
ind, val = n // 2, 0
ans, ind1 = a[ind], 1
for i in range(ind + 1, n):
val = (a[i] - a[i - 1]) * ind1
if k - val >= 0:
k -= val
ind1 += 1
ans = a[i]
else:
ans = a[i - 1] + k // ind1
k = 0
break
if k != 0:
ans += k // ind1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
a = a[len(a) // 2 :]
m = 1
while m < len(a) and k - (a[m] - a[0]) * m >= 0:
k -= (a[m] - a[0]) * m
a[0] = a[m]
m += 1
a[0] += k // m
print(a[0])
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
a, b = map(int, input().split())
z = sorted(map(int, input().split()))
def ok(mid):
clk = 0
for i in range(a // 2, a):
clk += max(0, mid - z[i])
if clk > b:
return False
return True
def bin_s():
lo, hi, ans = 1, 2 * int(1000000000.0), 0
while lo <= hi:
mid = (lo + hi) // 2
if ok(mid):
ans = mid
lo = mid + 1
else:
hi = mid - 1
return ans
print(bin_s())
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
p = [0] * (n // 2)
m = n // 2
ans = a[m]
s = 0
for i in range(m + 1, n):
p[i - m - 1] = a[i] - a[i - 1]
s += p[i - m - 1] * (i - m)
if k < s:
for i in range(m):
r = p[i] * (i + 1)
if k >= r:
k -= r
ans += p[i]
else:
ans += k // (i + 1)
break
else:
k -= s
ans = a[-1]
ans += k // (m + 1)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
def mp():
return map(int, input().split())
n, k = mp()
a = list(mp())
a.sort()
l = 1
r = 10**20
while l + 1 < r:
m = (l + r) // 2
s = 0
for i in range(n // 2, n):
s += max(0, m - a[i])
if k < s:
r = m
else:
l = m
print(l)
|
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
def check(x):
suma = 0
for i in range(n // 2, n):
suma += x - a[i]
if suma > k:
return False
if suma <= k:
return True
return False
n, k = [int(x) for x in input().split()]
a = list(map(int, input().split()))
a.sort()
l = 1
r = 2000000000
while l != r:
mid = (l + r + 1) // 2
if check(mid):
l = mid
else:
r = mid - 1
print(l)
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
A = sorted([int(x) for x in input().split()])
A += [2 * 10**9 + 1]
mid = n // 2
i = mid
result = -1
while k > 0:
while A[i] == A[i + 1]:
i += 1
d = A[i + 1] - A[i]
if (i + 1 - mid) * d <= k:
k -= (i + 1 - mid) * d
i += 1
result = A[i]
else:
result = A[i] + k // (i + 1 - mid)
k = 0
print(result)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
a, b = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
m = c[a // 2]
n = c[a // 2] + b
def check(mid):
s = 0
for i in range(a // 2, a):
if mid > c[i]:
s += mid - c[i]
else:
break
return s
while m <= n:
mid = (m + n) // 2
if check(mid) <= b:
m = mid + 1
else:
n = mid - 1
print(m - 1)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR RETURN VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
x = len(a) // 2
rem = 1
ans = a[x]
while k > 0:
if x + rem < len(a):
if k >= rem * (a[x + rem] - a[x + rem - 1]):
k -= rem * (a[x + rem] - a[x + rem - 1])
ans = a[x + rem]
rem += 1
else:
ans += k // rem
k = 0
else:
ans += k // rem
k = 0
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
import sys
n, k = [int(i) for i in input().split()]
data = [int(i) for i in input().split()]
if n == 1:
print(k + data[0])
sys.exit()
data.sort()
data = data[n // 2 :]
n = n // 2 + 1
sumto = [data[0]]
for i in range(1, n):
sumto.append(sumto[-1] + data[i])
ans = n - 1
for i in range(1, n):
am = i * data[i] - sumto[i - 1]
if am > k:
ans = i - 1
break
am = ans * data[ans] - sumto[ans - 1]
if ans == 0:
am = 0
left = k - am
extra = left // (ans + 1)
print(data[ans] + extra)
|
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
s = sorted(map(int, input().split()))
j = n // 2
i = n // 2
m = s[i]
def meadian(i, j, m, s, k):
while i < n - 1:
t = (s[i + 1] - m) * (i + 1 - j)
if t <= k:
k -= t
m = s[i + 1]
else:
break
i += 1
return m + k // (i + 1 - j)
print(meadian(i, j, m, s, k))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_DEF WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
S = list(map(int, input().split()))
S.sort()
S = S[n // 2 :]
ind = 0
while True:
if ind == n // 2 or k < ind + 1:
print(S[ind] + k // (n // 2 + 1))
break
else:
if S[ind] == S[ind + 1]:
ind += 1
continue
if (S[ind + 1] - S[ind]) * (ind + 1) <= k:
k -= (S[ind + 1] - S[ind]) * (ind + 1)
ind += 1
else:
print(S[ind] + k // (ind + 1))
break
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
def solve(a, n, k):
if n == 1:
return a[0] + k
a.sort()
total = sum(a[n // 2 :]) + k
avg = total // (n // 2 + 1)
remain = total % (n // 2 + 1)
element = n // 2 + 1
for i in range(n - 1, n // 2 - 1, -1):
if a[i] <= avg + remain and a[i - 1] <= avg:
return avg
else:
total -= a[i]
element -= 1
avg = total // element
remain = total % element
return a[n // 2] + k
n, k = map(int, input().split())
a = list(map(int, input().split()))
print(solve(a, n, k))
|
FUNC_DEF IF VAR NUMBER RETURN BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
def solve():
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a)
median = int(n / 2)
left = a[median]
right = 2 * 1000 * 1000 * 1000
while left < right:
middle = int((left + right + 1) / 2)
need = 0
for i in range(median, n, 1):
if a[i] < middle:
need += middle - a[i]
else:
break
if need > k:
right = middle - 1
else:
left = middle
print(left)
solve()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER NUMBER NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))[n // 2 :]
f = 1
i = 1
while k != 0 and i < len(a):
r = a[i] - a[0]
if r == 0:
f += 1
i += 1
continue
if f * r <= k:
a[0] += r
k -= r * f
else:
a[0] += k // f
k = 0
f += 1
i += 1
print(a[0] + k // len(a))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
b = list(map(int, input().split()))
b.sort()
m = b[(n - 1) // 2]
j = (n - 1) // 2
p = 1
while j < n - 1:
if k >= p * (b[j + 1] - b[j]):
m = b[j + 1]
k += -p * (b[j + 1] - b[j])
p += 1
j += 1
else:
break
print(m + k // p)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = [int(i) for i in input().split()]
ns = [int(i) for i in input().split()]
ns2 = ns
ns2.sort()
meio = n // 2
ns2 = ns2[meio:]
arrdif = []
arrdif.append(ns2[0])
for i, item in enumerate(ns2[1:]):
arrdif.append(item - ns[i + meio])
for i, dif in enumerate(arrdif[1:]):
if dif > 0:
aux = dif * (i + 1)
if k >= aux:
k -= aux
arrdif[0] += aux // (i + 1)
else:
arrdif[0] += k // (i + 1)
k = 0
if k == 0:
break
if k > 0:
arrdif[0] += k // len(arrdif)
print(arrdif[0])
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = sorted(map(int, input().split()))
if n == 1:
print(k + a[0])
raise SystemExit
d = [a[0]] + [(a[i + 1] - a[i]) for i in range(len(a) - 1)]
for i in range(n // 2 + 1, n):
if k <= 0:
break
e = min(k // (i - n // 2), d[i])
d[n // 2] += e
d[i] -= e
k -= e * (i - n // 2)
d[n // 2] += k // (n - n // 2)
r = 0
for i in range(n // 2 + 1):
r += d[i]
print(r)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP LIST VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
def max_median(n, m, lst):
j, r = n // 2, n // 2 + 1
while m and r < n:
if lst[j] == lst[r]:
r += 1
else:
t = min(m, (lst[r] - lst[j]) * (r - j))
lst[j] += t // (r - j)
m -= t
if lst[j] == lst[n - 1]:
return lst[j] + m // (n - j)
return lst[j] + min(m, (lst[r] - lst[j]) * (r - j)) // (r - j)
N, K = [int(i) for i in input().split()]
a = [int(x) for x in input().split()]
print(max_median(N, K, sorted(a)))
|
FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR RETURN BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
def get_from_str(string: str):
return list(map(int, string.split(" ")))
def test(string: str):
param, data = string.split("\n")
n, k = get_from_str(param)
numbers = get_from_str(data)
compute(n, k, numbers)
def sort_numbers(list_of_numbers):
return sorted(list_of_numbers)
def find_bigger(numbers):
first = numbers[0]
if numbers[-1] == first:
return False
if numbers[1] > first:
return 1
left = 0
right = len(numbers)
while right - left > 1:
center = (right + left) // 2
if numbers[center] > numbers[left]:
right = center
else:
left = center
if numbers[left] > first:
return left
else:
return right
def find_valid_area(numbers, k):
first = numbers[0]
if numbers[-1] == first:
return k // len(numbers)
left = 0
right = len(numbers)
center = 0
while right - left > 1:
center = (right + left) // 2
height = numbers[center]
area = height * center - sum(numbers[:center])
if area > k:
right = center
else:
left = center
return (k + sum(numbers[:right])) // len(numbers[:right])
def compute(n, k, numbers):
part_1 = sort_numbers(numbers)
part_2 = part_1[n // 2 :]
part_3 = [(item - part_2[0]) for item in part_2]
inc = find_valid_area(part_3, k)
med = part_2[0] + inc
print(med)
n_gl, k_gl = get_from_str(input())
numbers_gl = get_from_str(input())
compute(n_gl, k_gl, numbers_gl)
|
FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF VAR ASSIGN VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR RETURN NUMBER IF VAR NUMBER VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR RETURN VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR RETURN BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
a.sort()
median = a[n // 2]
mid = n // 2
if n == 1:
print(a[0] + k)
else:
if k <= a[mid + 1] - a[mid]:
median += k
else:
median = a[mid + 1]
k -= a[mid + 1] - a[mid]
req = 0
f = 2
for i in range(mid + 1, n - 1):
req = (a[i + 1] - a[i]) * f
if k >= req:
median = a[i + 1]
else:
median += k // f
k -= req
break
k -= req
f += 1
if k > 0:
median += k // (mid + 1)
print(median)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
s = 0
c = 1
v = []
for i in range(n // 2 + 1, n):
v.append(c * (l[i] - l[i - 1]))
c += 1
ans = 0
for i in range(len(v)):
if k > 0 and v[i] > 0:
m = min(v[i], k)
ans += m // (i + 1)
k -= m
if k > 0:
ans += k // (len(v) + 1)
print(ans + l[n // 2])
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
from sys import stdin
def check(num, arr, k):
i = len(arr) - 1
while i >= len(arr) // 2:
if arr[i] >= num:
pass
else:
k -= abs(num - arr[i])
i -= 1
if k >= 0:
return True
else:
return False
n, k = list(map(int, stdin.readline().split()))
arr = list(map(int, stdin.readline().split()))
arr.sort()
middle = arr[n // 2]
start = middle
end = middle + k
while True:
if start >= end:
if check(start + 1, arr, k):
start += 1
break
mid = (start + end) // 2
if check(mid, arr, k):
start = mid + 1
else:
end = mid - 1
if check(start, arr, k):
print(start)
else:
print(start - 1)
|
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE NUMBER IF VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
a = a[n // 2 :]
n = n // 2 + 1
n_inc = 1
while m > 0:
while n_inc < n and a[n_inc - 1] == a[n_inc]:
n_inc += 1
if n_inc == n:
to_inc = m // n_inc
else:
to_inc = min(m // n_inc, a[n_inc] - a[n_inc - 1])
total_inc = n_inc * to_inc
m -= total_inc
a[n_inc - 1] += to_inc
if n_inc == n or to_inc == 0:
break
print(a[n_inc - 1])
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = sorted([int(x) for x in input().split()])[int(n / 2) :]
n = len(a)
l = a[0]
h = a[n - 1] + k // n
ans = 0
def find(m):
moves = 0
for i in range(n):
if m - a[i] > 0:
moves += m - a[i]
if moves > k:
return False
if moves > k:
return False
return True
while l <= h:
m = (l + h) // 2
if find(m):
ans = max(ans, m)
l = m + 1
else:
h = m - 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
index = n // 2
a.sort()
def f(x):
if a[index] >= x:
return True
tmp = k
for val in a[index:]:
if val >= x:
return True
tmp -= x - val
if tmp < 0:
return False
return True
l = a[index]
r = l + k
ans = l
while l <= r:
mid = (l + r) // 2
if f(mid):
ans = mid
l = mid + 1
else:
r = mid - 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_DEF IF VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR FOR VAR VAR VAR IF VAR VAR RETURN NUMBER VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
ind = n // 2 + 1
mid = n // 2
median = a[mid]
while ind < n and a[ind] == median:
ind += 1
while k >= ind - mid:
median += 1
k -= ind - mid
while ind < n and a[ind] == median:
ind += 1
print(median)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER WHILE VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
def f(tar, l, k):
req = 0
for i in range(len(l)):
req += max(0, tar - l[i])
if req <= k:
return True
else:
return False
n, k = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
l = l[n // 2 :]
low, high, ans = l[0], 10**18, 0
while low <= high:
mid = low + (high - low) // 2
x = f(mid, l, k)
if x:
ans = max(ans, mid)
low = mid + 1
else:
high = mid - 1
print(ans)
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER BIN_OP NUMBER NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
l.sort()
l = l[n // 2 :]
while k != 0:
mini = l[0]
compte = l.count(mini)
if compte == len(l):
reste = k // len(l)
l[0] += reste
k = 0
break
deux_mini = l[compte]
diff = deux_mini - mini
if k >= diff * compte:
k -= diff * compte
for i in range(compte):
l[i] = deux_mini
else:
reste = k // compte
l[0] += reste
k = 0
break
print(l[0])
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
print(a[0] + k)
else:
a.sort()
n = (n - 1) // 2
a = a[n:]
med = a[0]
for i in range(0, n):
add = min((a[i + 1] - a[i]) * (i + 1), k)
k -= add
med += add // (i + 1)
med += k // (n + 1)
print(med)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
def check(x, a):
moves = 0
for i in range(n // 2, n):
if x - a[i] > 0:
moves += x - a[i]
if moves > k:
return False
if moves <= k:
return True
else:
return False
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
a = sorted(a)
j = n // 2
r = n // 2 + 1
s = 1
b = 20000000000
while s != b:
mid = (s + b) // 2 + 1
if check(mid, a):
s = mid
else:
b = mid - 1
print(s)
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
import sys
def main():
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
arr.append(10**12)
median = arr[n >> 1]
i = n // 2
while i <= n - 1 and arr[i + 1] == median:
i += 1
cnt = i + 1 - n // 2
while i <= n:
i += 1
while i <= n - 1 and arr[i + 1] == arr[i]:
i += 1
diff = arr[i] - median
if diff * cnt > k:
ans = median + k // cnt
break
else:
median += diff
k -= cnt * diff
cnt = i + 1 - n // 2
print(ans)
return 0
main()
|
IMPORT FUNC_DEF IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
m = [int(a) for a in input().split()]
m.sort()
del m[0 : n // 2]
n = len(m)
a = 1
while k > 0:
if a < n and k - a * (m[a] - m[0]) >= 0:
k = k - a * (m[a] - m[0])
m[0] += m[a] - m[0]
a += 1
else:
m[0] += k // a
k = 0
print(m[0])
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
s = list(map(int, input().split()))
s.sort()
t = s[-(n // 2)] - s[n // 2]
if k <= t or n == 1:
print(s[n // 2] + k)
else:
s = s[n // 2 :]
ans = s[0]
t = s[0]
s = list(filter(lambda x: x <= k, map(lambda x: x - t, s)))
t = s[0]
i = 1
while i < len(s) and k >= 0:
d = i
if d * (s[i] - s[i - 1]) <= k:
k -= d * (s[i] - s[i - 1])
ans += s[i] - s[i - 1]
else:
ans += k // d
break
i += 1
if i == len(s):
ans += k // (d + 1)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = sorted(map(int, input().split()))
a += [10**10]
m = (n - 1) // 2
med = 0
sum1 = 0
for i in range(m, n):
sum1 += a[i]
c = min(a[i + 1], (k + sum1) // (i + 1 - m))
if c < a[i]:
break
if c > med:
med = c
print(med)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
length, moves = [int(x) for x in input().split()]
inp = [int(x) for x in input().split()]
middle = int((length + 1) / 2)
ans = int()
sameind = 0
counter = 0
inp.sort()
while moves > sameind:
for i in range(middle + sameind, length):
if inp[i] == inp[middle + sameind - 1]:
sameind += 1
if middle + sameind < length:
nextdiff = inp[middle + sameind] - inp[middle + sameind - 1]
if (sameind + 1) * nextdiff <= moves:
moves -= (sameind + 1) * nextdiff
counter += nextdiff
else:
counter += int(moves / (sameind + 1))
moves -= (sameind + 1) * int(moves / (sameind + 1))
else:
counter += int(moves / (sameind + 1))
moves -= (sameind + 1) * int(moves / (sameind + 1))
sameind += 1
print(counter + inp[middle - 1])
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR WHILE VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
def good(m, a, k):
x = 0
for i in range(n // 2, n):
if m - a[i] > 0:
x += m - a[i]
if x <= k:
return 1
else:
return 0
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
l = 1
r = 10**11
while r > l + 1:
m = (l + r) // 2
if good(m, a, k) == 1:
l = m
else:
r = m
print(l)
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
m = a[-1]
s = 0
for i in a[n // 2 :]:
s += m - i
if s <= k:
ma = (sum(a[n // 2 :]) + k) // (1 + n // 2)
print(ma)
else:
a = a[n // 2 :]
s = 0
li = 0
for i in range(len(a) - 1):
if (a[i + 1] - a[i]) * (i + 1) + s > k:
li = i
break
s += (a[i + 1] - a[i]) * (i + 1)
print(((li + 1) * a[li] + (k - s)) // (1 + li))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
id = n // 2
for i in range(n // 2, n - 1):
if (a[i + 1] - a[i]) * (i + 1 - id) > k:
print(a[i] + k // (i + 1 - id))
return
else:
k -= (a[i + 1] - a[i]) * (i + 1 - id)
print(a[-1] + k // (n - id))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
data = list(map(int, input().split()))
data.sort()
data = data[n // 2 :]
now = data[0]
cnt = 0
for i in data:
if k - (i - now) * cnt >= 0:
k -= (i - now) * cnt
else:
break
now = i
cnt += 1
if k > 0:
now += k // cnt
print(now)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
from sys import stdin
def ii():
return int(stdin.readline())
def mi():
return map(int, stdin.readline().split())
def li():
return list(mi())
n, k = mi()
m = n // 2
a = li()
a.sort()
p = a[m]
b = []
x = 1
for j in range(m + 1, n):
y = a[j] - p
p += min(y, k // x)
k -= y * x
if k >= 0:
x += 1
else:
break
if k > 0:
p += k // (m + 1)
print(p)
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = [int(i) for i in input().split(" ")]
a = sorted([int(i) for i in input().split(" ")])
ans = a[n // 2]
tot = 0
for i in range(n // 2 + 1, n, 1):
last = tot
tot += (i - n // 2) * (a[i] - a[i - 1])
if tot >= k:
ans = ans + (k - last) // (i - n // 2)
break
ans = a[i]
if tot < k:
ans = ans + (k - tot) // (n - n // 2)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
m = n // 2
p = m
l = a[p]
while True:
if p < n - 1:
if l < a[p + 1]:
if k < p - m + 1:
print(l)
exit()
k -= p - m + 1
l += 1
else:
p += 1
else:
print(l + k // (p - m + 1))
exit()
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR WHILE NUMBER IF VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
m = n // 2
p = a[m]
t = k
c = 1
for i in range(m + 1, n):
d = a[i] - p
r = t - c * d
if r == 0:
print(a[i])
exit()
elif r < 0:
print(a[i - 1] + t // c)
exit()
else:
c += 1
p = a[i]
t = r
print(a[n - 1] + t // c)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
lo = 0
hi = 2000000000
def check(b, m, x):
size = len(b)
b.sort()
need = 0
for i in range(size // 2, size):
need += max(0, m - b[i])
if k >= need:
return 1
return 0
while lo != hi:
mid = (lo + hi + 1) // 2
if check(a, mid, k):
lo = mid
else:
hi = mid - 1
print(hi)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
def solver(v, p):
for i in range(n // 2, n):
if arr[i] <= v:
t = v - arr[i]
p = p - t
if p >= 0:
return True
else:
return False
start = 1
end = 10**14
while end - start > 1:
mid = (start + end) // 2
if solver(mid, k) == True:
start = mid
else:
end = mid
if solver(start, k) == True:
print(start)
else:
print(end)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
l = input().split()
n = int(l[0])
k = int(l[1])
l = input().split()
li = [int(i) for i in l]
li.append(1000000000000)
li.sort()
curr = n // 2
slot = 1
ans = li[curr]
while 1:
possible = (li[curr + 1] - li[curr]) * slot
if k >= possible:
ans = li[curr + 1]
curr += 1
slot += 1
k -= possible
else:
ans += k // slot
break
print(ans)
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = list(sorted(map(int, input().split())))[n // 2 :]
n = len(a)
def f(x):
return sum(max(0, x - a[i]) for i in range(n))
l, r = a[0], 2 * 10**9 + 2
while r - l > 1:
m = (l + r) // 2
if f(m) <= k:
l = m
else:
r = m
if f(r) <= k:
print(r)
else:
print(l)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
d = input().split(" ")
d = [int(i) for i in d]
a = input().split(" ")
a = [int(i) for i in a]
a = sorted(a)
def can(m):
sum = 0
for i in range(d[0] // 2, d[0]):
if m > a[i]:
sum += m - a[i]
return d[1] >= sum
l = 0
r = int(1e17)
while r - l > 1:
m = (r + l) // 2
if can(m):
l = m
else:
r = m
print(l)
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR VAR RETURN VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
temp = input()
temp = temp.split(" ")
n = int(temp[0])
k = int(temp[1])
temp = input()
temp = temp.split(" ")
a = []
for i in range(n):
a.append(int(temp[i]))
a.sort()
mid = int(n / 2)
move = 0
j = mid
i = mid + 1
while i < n:
if move + (a[i] - a[i - 1]) * (i - mid) <= k:
move = move + (a[i] - a[i - 1]) * (i - mid)
j = i
else:
break
i += 1
left = k - move
ans = a[j]
ans += int(left / (j - mid + 1))
print(ans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
a, b = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
m = a // 2
s = 0
s += A[m]
k = 1
t = True
m += 1
while t == True and m < a:
if A[m] * k - s >= b:
t = False
else:
s += A[m]
k += 1
m += 1
q = A[m - 1] * k
v = q - s
b -= v
e = b // k
print(A[m - 1] + e)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
m = a[n // 2]
c = 1
for i in range(n // 2 + 1, n):
if k >= (a[i] - m) * c:
k = k - (a[i] - m) * c
m = a[i]
c = c + 1
else:
m = m + k // c
k = 0
break
print(m + k // c)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, m = [int(x) for x in input().split()]
s = [int(x) for x in input().split()]
s.sort()
k = (n - 1) // 2
ind = k + 1
med = s[k]
while m >= 0:
if ind == n:
med += m // (ind - k)
break
m -= (s[ind] - med) * (ind - k)
med = s[ind]
ind += 1
if m < 0:
ind -= 1
med -= -m // (ind - k)
if -m % (ind - k):
med -= 1
print(med)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR NUMBER IF VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
from sys import stdin
def iin():
return int(stdin.readline())
def lin():
return list(map(int, stdin.readline().split()))
n, k = lin()
a = lin()
if n == 1:
print(a[0] + k)
else:
a.sort()
h = n // 2
ch1 = 0
ch2 = h + 1
for i in range(h + 1, n):
if (a[i] - a[i - 1]) * (i - h) <= k:
mn = (a[i] - a[i - 1]) * (i - h)
k -= mn
else:
ch1 = 1
ch2 = i
for j in range(h, i):
a[j] = a[i - 1]
break
else:
for j in range(h, n):
a[j] = a[-1]
rng = h + 1
if ch1:
rng = ch2 - h
su = k // rng
if su:
for i in range(h, h + rng):
a[i] += su
for i in range(k % rng):
a[h + i] += 1
a.sort()
print(a[h])
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
[n, k] = list(map(int, input().split()))
s = list(map(int, input().split()))
s = sorted(s)
sum = 0
pos = n // 2
for i in range(n // 2, n - 1):
sum = sum + s[n - 1] - s[i]
if k >= sum:
res = s[n - 1] + (k - sum) // (n // 2 + 1)
else:
for i in range(n - 2, n // 2 - 1, -1):
sum = sum - pos * (s[i + 1] - s[i])
if k >= sum:
res = s[i] + (k - sum) // pos
else:
pos = pos - 1
continue
print(res)
|
ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
q = sorted(map(int, input().split()))[int(n / 2) : n]
median = q[0]
op = 1
for i in range(1, len(q)):
if (q[i] - median) * op <= k:
k -= (q[i] - median) * op
median = q[i]
else:
break
op += 1
print(median + int(k / op))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
med = a[n // 2]
low = med
high = 2 * 10**9 + 1
while low + 1 < high:
mid = (low + high) // 2
total = 0
for el in a[n // 2 :]:
if el < mid:
total += mid - el
if total > k:
low, high = low, mid
else:
low, high = mid, high
print(low)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
mid = n // 2
itr = 1
tot = 0
for i in range(mid + 1, n):
if tot + (arr[i] - arr[i - 1]) * itr > k:
break
else:
tot += (arr[i] - arr[i - 1]) * itr
itr += 1
final = arr[mid + itr - 1] + (k - tot) // itr
print(final)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
s = n // 2
l = 1
r = int(10000000000.0)
while l < r:
m = (l + r + 1) // 2
cnt = 0
for i in range(s, n):
cnt += max(0, m - a[i])
if cnt <= k:
l = m
else:
r = m - 1
print(l)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
A = sorted(map(int, input().split()), reverse=True)
MIN = 1
MAX = max(A) + k
while MIN != MAX:
AVE = (MIN + MAX + 1) // 2
score = 0
for i in range(n // 2 + 1):
if AVE > A[i]:
score += AVE - A[i]
if score > k:
MAX = AVE - 1
else:
MIN = AVE
print(MIN)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
mid = n // 2
def predicate(x):
add = 0
for i in range(mid, n):
add += max(x - arr[i], 0)
return add <= k
def bs(start, end):
ans = None
while start <= end:
mid = start + end >> 1
if predicate(mid):
ans = mid
start = mid + 1
else:
end = mid - 1
return ans
ans = bs(0, 2 * pow(10, 9) + 100)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR NONE WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
a.sort()
a = a[n // 2 :] + [10**10]
for i in range(1, len(a)):
prev = a[i - 1]
curr = a[i]
if (curr - prev) * i <= k:
a[0] = curr
k -= (curr - prev) * i
else:
val = k // i
a[0] += val
break
print(a[0])
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER LIST BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = sorted(map(int, input().split()))[n // 2 :]
i = 0
s = 0
while i < len(a):
s += a[i]
if a[i] * (i + 1) - s > k:
break
i += 1
k -= a[i - 1] * i - sum(a[:i])
print(a[i - 1] + k // i)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = list(map(int, input().split()))
arr = sorted(list(map(int, input().split())))
median = arr[n // 2]
jumps = []
for i in range(n // 2 + 1, n):
jumps.append(arr[i] - arr[i - 1])
for i in range(len(jumps)):
weight = i + 1
if weight * jumps[i] > k:
this_jump = k // weight
median += this_jump
k -= this_jump * weight
break
k -= weight * jumps[i]
median += jumps[i]
weight = n // 2 + 1
median += k // weight
print(median)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
r = k
m = (n - 1) // 2
p = m + 1
v = a[m]
while p < n:
u = (p - m) * (a[p] - v)
if u <= r:
v = a[p]
r -= u
else:
break
p += 1
d = r // (p - m)
u = d * (p - m)
r -= u
v = v + d
print(v)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
i = 0
s = 0
d = n // 2 + 1
res = l[n // 2]
for j in range(n // 2 + 1, n):
i += 1
if k >= i * (l[j] - l[j - 1]):
s += i * (l[j] - l[j - 1])
k -= i * (l[j] - l[j - 1])
res += l[j] - l[j - 1]
else:
d = i
break
if k // d != 0:
res += k // d
print(res)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
u = list(map(int, input().split()))
u.sort()
if n == 1:
print(u[0] + k)
exit()
ans = u[n // 2]
num = 1
for i in range(n // 2 + 1, n):
if (u[i] - u[i - 1]) * (i - n // 2) <= k:
k -= (u[i] - u[i - 1]) * (i - n // 2)
ans = u[i]
num += 1
else:
break
ans += k // num
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
import sys
n, k = list(map(int, sys.stdin.readline().strip().split()))
a = list(map(int, sys.stdin.readline().strip().split()))
m = n // 2
a.sort()
d = 1
ans = a[m]
if ans != a[n - 1]:
while ans == a[m + d]:
d = d + 1
else:
d = n // 2 + 1
while d <= k and k > 0:
k = k - d
ans = ans + 1
if ans < a[n - 1]:
while ans == a[m + d]:
d = d + 1
else:
d = n // 2 + 1
print(ans)
|
IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = [int(a) for a in input().split()]
a = list(map(int, input().split()))
m = n // 2
a.sort()
l = 1
r = int(2000000000.0)
while l != r:
mid = (l + r + 1) // 2
tmp = 0
for i in range(m, n):
if mid - a[i] > 0:
tmp += mid - a[i]
if tmp > k:
r = mid - 1
if tmp <= k:
l = mid
print(l)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
md = n // 2
lo = l[md]
hi = int(10000000000.0)
ans = l[md]
while lo <= hi:
mid = (lo + hi) // 2
reqk = 0
for i in range(n // 2, n):
if l[i] < mid:
reqk += mid - l[i]
if reqk <= k:
ans = mid
lo = mid + 1
else:
hi = mid - 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
same = 1
mid = n // 2
while k > 0:
if same <= mid:
diff = l[mid + same] - l[mid]
temp = k
k -= diff * same
if k >= 0:
l[mid] = l[mid + same]
else:
l[mid] = l[mid] + temp // same
else:
l[mid] = l[mid] + k // same
k = 0
same += 1
print(l[mid])
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
def binarySearch(arr, l, r, x):
mid = int(l + (r - l) / 2)
if r >= l:
if arr[mid] == x:
return mid
elif arr[mid] > x:
return binarySearch(arr, l, mid - 1, x)
else:
return binarySearch(arr, mid + 1, r, x)
else:
return mid
les, k = list(map(int, input().split()))
nums = list(map(int, input().split()))
nums.sort()
nums = nums[les // 2 :]
hbNum = 1
hbValue = nums[0]
del nums[0]
while k > 0:
while len(nums) > 0 and hbValue == nums[0]:
del nums[0]
hbNum += 1
try:
taller = (nums[0] - hbValue) * hbNum
except:
taller = "fuck"
if taller != "fuck" and k >= taller:
hbValue = nums[0]
k -= taller
else:
hbValue += k // hbNum
k = 0
print(hbValue)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR IF VAR VAR VAR RETURN VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR STRING IF VAR STRING VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
def check(mid):
ans = 0
for i in range(n // 2 + 1):
ans += max(0, mid - a[i])
if ans <= k:
return True
return False
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
l, r = 1, 10**10
while l != r:
mid = (l + r + 1) // 2
if check(mid):
l = mid
else:
r = mid - 1
print(l)
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
a.append(10**57)
m = n // 2
for i in range(m, n):
p = (i - m + 1) * (a[i + 1] - a[i])
if k < p:
break
k -= p
print(a[i] + k // (i - m + 1))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
def possible(l, mid, k, n):
add = 0
for i in range(n // 2, n):
if mid - l[i] > 0:
add += mid - l[i]
if add > k:
return 1
if add <= k:
return 0
else:
return 1
n, m = map(int, input().split())
l = list(map(int, input().split()))
low = 1
high = m + max(l)
l.sort()
while low <= high:
mid = (low + high) // 2
if possible(l, mid, m, n) == 0:
low = mid + 1
else:
high = mid - 1
print(low - 1)
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
st = n // 2
cur = arr[st]
cnt = 1
f = 0
for i in range(st + 1, n):
diff = arr[i] - cur
if diff * cnt <= k:
k -= diff * cnt
cnt += 1
cur = arr[i]
else:
f = 1
break
if f == 0:
cur += k // (st + 1)
else:
cur += k // cnt
print(cur)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().strip().split())
numbers = list(map(int, input().strip().split()))
numbers.sort()
p = numbers[n // 2]
s = 0
t = 0
for i in range(n // 2, n - 1):
p1 = (k - s) // (i - n // 2 + 1)
s = s + min(p1, numbers[i + 1] - p) * (i - n // 2 + 1)
t = t + min(p1, numbers[i + 1] - p)
if p1 < numbers[i + 1] - p:
break
p = numbers[i + 1]
else:
t = t + (k - s) // (n // 2 + 1)
print(t + numbers[n // 2])
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
idxAns = int(n / 2)
ans = arr[idxAns]
while k > 0:
idx = idxAns + 1
while idx < n:
if ans != arr[idx]:
break
idx += 1
if idx == n:
x = n - idxAns
ans += int(k / x)
k = 0
else:
minimum = min(k, (arr[idx] - ans) * (idx - idxAns))
if minimum == k and minimum == (arr[idx] - ans) * (idx - idxAns):
ans += arr[idx] - ans
elif minimum == (arr[idx] - ans) * (idx - idxAns):
for i in range(idxAns, idx):
arr[i] += arr[idx] - ans
ans = arr[idxAns]
else:
ans += int(k / (idx - idxAns))
k -= minimum
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR IF VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
arr = list(map(int, input().split()))
if n == 1:
print(arr[0] + k)
exit(0)
arr.sort()
mid = n // 2
piv = mid + 1
maxm = arr[mid]
delta = arr[mid + 1] - arr[mid]
while k >= delta:
k -= delta
maxm = arr[piv]
piv += 1
if piv >= n:
break
delta = (piv - mid) * (arr[piv] - maxm)
if piv != mid:
maxm += k // (piv - mid)
print(maxm)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = list(map(int, input().split()))
ai = list(map(int, input().split()))
ai.sort()
num = n // 2
num2 = num
ans = ai[num]
n2 = n - 1
while num != n2 and k > 0:
num += 1
k -= (ai[num] - ai[num - 1]) * (num - num2)
if k < 0:
print(ai[num] + k // (num - num2))
else:
print(ai[num] + k // (num - num2 + 1))
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
from sys import exit, stdin, stdout
n, k = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
a.sort()
a = a[(n - 1) // 2 :]
sums = [0]
total = 0
for i in range((n + 1) // 2):
total += a[i]
sums.append(total)
def doable(tgt):
if a[0] >= tgt:
return True
ct = 0
hi = (n + 1) // 2
while ct + 1 < hi:
mid = (ct + hi) // 2
if a[mid] < tgt:
ct = mid
else:
hi = mid
return tgt * (ct + 1) - sums[ct + 1] <= k
lo = 1
hi = 10**15
while lo + 1 < hi:
mid = (lo + hi) // 2
if doable(mid):
lo = mid
else:
hi = mid
stdout.write(str(lo) + "\n")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
from sys import stdin, stdout
N, K = [int(x) for x in stdin.readline().split()]
arr = [int(x) for x in stdin.readline().split()]
arr.sort()
half = N // 2
s = sum(arr[half:])
bound = s + K
res = 0
for i in range(N - 1, N // 2 - 1, -1):
if bound // (i - half + 1) > arr[i]:
res = max(res, bound // (i - half + 1))
if i != N - 1 and res > arr[i + 1]:
res = arr[i + 1]
break
else:
bound -= arr[i]
print(res)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
l = 1
jog = 0
ans = 0
if n == 1:
print(a[0] + k)
else:
for i in range(int((n - 1) / 2), n - 1):
jog += l * (a[i + 1] - a[i])
if jog > k:
jog -= l * (a[i + 1] - a[i])
ans = a[i] + int((k - jog) / l)
break
l += 1
if ans != 0:
print(ans)
else:
ans = a[i + 1] + int((k - jog) / l)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
def f(v, mid, N, K):
last_max = v[N // 2] + mid
cur = K - mid
for i in range(N // 2 + 1, N):
needed = last_max - v[i]
if needed > 0:
cur -= needed
if cur < 0:
return False
else:
break
return True
def main():
N, K = map(int, input().split())
v = list(map(int, input().split()))
v.sort()
s, e, mid, sol = 0, K, 0, 0
while s <= e:
mid = s + (e - s) // 2
if f(v, mid, N, K):
s = mid + 1
sol = mid
else:
e = mid - 1
print(v[N // 2] + sol)
main()
|
FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = list(map(int, input().split()))[:2]
a = list(map(int, input().split()))
a = sorted(a)
b = a[n // 2 :]
diff = []
for i in range(1, len(b)):
di = i * (b[i] - b[i - 1])
diff.append(di)
ans = b[0]
for i in range(len(diff)):
if k < diff[i]:
ans = ans + k // (i + 1)
k = 0
break
else:
k -= diff[i]
ans = b[i + 1]
ans = ans + k // len(b)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = map(int, input().split())
s = sorted(list(map(int, input().split())))
s[0 : n // 2] = []
med = 0
if n == 1:
print(s[0] + k)
else:
i = 0
while k > (i + 1) * (s[i + 1] - s[i]):
k = k - (i + 1) * (s[i + 1] - s[i])
i += 1
if i == n // 2:
break
med = s[i] + k // (i + 1)
print(med)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER LIST ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: 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$).
You want to make the median of the array the largest possible using at most $k$ operations.
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$.
-----Input-----
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.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
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$.
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
mid = n // 2
count = 1
Sum = a[mid]
res = a[mid]
index = -1
for i in range(mid + 1, n):
if count * a[i] - Sum <= k:
count += 1
Sum += a[i]
res = a[i]
else:
index = i
break
if index == -1:
k = max(0, k - (count * a[-1] - Sum))
res += k // (mid + 1)
print(res)
else:
k = max(0, k - (count * a[index - 1] - Sum))
res += k // (index - mid)
print(res)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.