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$ operatio...
def bi(a, x): l = -1 u = len(a) while u - l > 1: md = int((l + u) / 2) if x >= a[md]: l = md else: u = md return u - 1 n, k = map(int, input().split()) a = list(map(int, input().split())) a = sorted(a) diff = [0] * (n // 2 + 1) for i in range(1, n // 2 +...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FU...
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$ operatio...
y = lambda: map(int, input().split()) n, k = y() a = sorted(y()) + [(1 << 31) - 1] d = 1 i = n // 2 v = a[i] while k >= d: while d < n - i and v == a[i + d]: d += 1 r = min(k // d, a[i + d] - v) v += r k -= d * r print(v)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR LIST BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR WHILE VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FU...
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$ operatio...
def read_ints(): return map(int, input().split(" ")) n, k = read_ints() a = list(read_ints()) a.sort() idx = n // 2 length = 1 ans = a[idx] while idx < n - 1 and k >= length: nxt = a[idx + 1] delta = min(nxt - a[idx], k // length) k -= delta * length ans = a[idx] + delta idx += 1 length +=...
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP V...
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$ operatio...
line = input() tmp1 = line.split(" ") n, m = int(tmp1[0]), int(tmp1[1]) line1 = input() num = [int(i) for i in line1.split(" ")] num = sorted(num) j = n // 2 r = n // 2 + 1 while m and r < n: if num[j] == num[r]: r += 1 else: t = min(m, (num[r] - num[j]) * (r - j)) num[j] += t // (r - j)...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE 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$ operatio...
n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() a.reverse() def ok(center): global a, k, n kneed = 0 for I in a[0 : n // 2 + 1]: kneed += max(0, center - I) if kneed <= k: return True else: return False L = 0 R = a[0] + k + 1 while R - L > 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 FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER A...
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$ operatio...
n, k = [int(i) for i in input().split()] l = [int(i) for i in input().split()] l.sort() def actually_ok(l, m, kk): k = kk for i in range(len(l) - 1, int(n / 2) - 1, -1): if l[i] > m: return False k -= m - l[i] if k < 0: return False else: return True def o...
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_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR RETURN NUMBER 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$ operatio...
n, k = map(int, input().split()) assert n % 2 == 1 arr = sorted(map(int, input().split())) arr = arr[n // 2 :] med = arr[0] for i in range(1, len(arr)): if k == 0: break if arr[i] == med: continue else: diff = arr[i] - med kdiff = min(diff * i, k) med += kdiff // i ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN 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$ operatio...
n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) mid = n // 2 if n == 1: print(a[0] + k) exit() t = k k -= min(a[mid + 1] - a[mid], k) if k == 0: print(a[mid] + t) exit() a[mid] += a[mid + 1] - a[mid] c = 1 for i in range(mid + 1, n): if a[i] == a[mid]: c += 1 ...
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 IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR IF VA...
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$ operatio...
n, k = map(int, input().split(" ")) arr = [int(i) for i in input().split(" ")] arr.sort() l, r = arr[n // 2], int(2000000000.0 + 5) while l < r: mid = (l + r + 1) // 2 reqd = 0 for i in range(n // 2, n): reqd += max(mid - arr[i], 0) if reqd > k: r = mid - 1 else: l = mid prin...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CA...
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$ operatio...
n, k = map(int, input().strip().split()) a = list(map(int, input().strip().split())) a.sort() m = int(n // 2) flag = 0 v = a[m] r = 0 for i in range(m + 1, n): p = r + (a[i] - a[i - 1]) * (i - m) if p < k: r = p else: v = a[i - 1] + int((k - r) // (i - m)) flag = 1 break if f...
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 FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_...
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$ operatio...
n, m = map(int, input().split()) A = list(map(int, input().split())) t = n // 2 s = m i = 1 k = 0 A.sort() while t < n: s += A[t] k = s // i if t != n - 1 and k <= A[t + 1]: break t += 1 i += 1 print(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 VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR WHILE VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR N...
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$ operatio...
n, k = list(map(int, input().split())) arr = list(map(int, input().split())) arr.sort() curr = arr[n // 2] count = 1 for i in range(n // 2 + 1, n): diff = arr[i] - curr if diff and diff * count <= k: k -= diff * count curr += diff elif diff and diff * count > k: curr += k // count ...
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 ASSIGN VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR VA...
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$ operatio...
n, k = map(int, input().split()) data = list(map(int, input().split())) data.sort() mid = n // 2 arr = data[mid:] mid = arr[0] for i in range(1, len(arr)): count = arr[i] - arr[i - 1] if k >= count * i: k -= count * i mid += count else: mid += k // i k = 0 if k: mid += 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 EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_O...
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$ operatio...
n, k = map(int, input().split()) l = list(map(int, input().split())) def median(arr, k): arr.sort() n = (len(arr) - 1) // 2 arr = arr[n:] while k > 0: m = arr.count(arr[0]) if m == len(arr): return arr[0] + k // m x = arr[m] ecart = x - arr[0] if m *...
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 EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN BIN_OP ...
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$ operatio...
n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() mid = n // 2 for i in range(mid, n - 1): if k - (a[i + 1] - a[i]) * (i - mid + 1) >= 0: k -= (a[i + 1] - a[i]) * (i - mid + 1) else: exit(print(k // (i - mid + 1) + a[i])) print(k // (n - mid) + a[-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 BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP...
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$ operatio...
I = lambda: map(int, input().split()) n, k = I() a = sorted(I()) q, w, z = n // 2, 1, a[n // 2] for i in range(q, n - 1): t = (a[i + 1] - a[i]) * w if k >= t: k -= t z = a[i + 1] w += 1 else: break print(z + k // w)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR VAR VAR ASSIGN 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$ operatio...
n, k = map(int, input().split()) numbers = [int(i) for i in input().split()] numbers.sort() l = numbers[0] r = numbers[-1] + k m = n // 2 while l <= r: mid = (l + r) // 2 tmp = 0 for i in numbers[m:]: if i < mid: tmp += mid - i else: break if tmp <= k: l =...
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 VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF 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$ operatio...
def valid(a, mid, n, k): tot = 0 x = int((n - 1) / 2) for i in range(x, n): tot += max(0, mid - a[i]) if tot <= k: return True return False n, k = [int(x) for x in input().split()] a = [int(x) for x in input().split()] a.sort() s = 0 e = 10000000000 while s <= e: mid = int((s +...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR ...
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$ operatio...
n, k = input().split() intn = int(n) intk = int(k) a = list(map(int, input().strip().split()))[:intn] a.sort() l = 2000000000 s = 0 ans = 0 while s <= l: mid = (s + l) // 2 su = 0 for i in range(intn // 2, intn): su = su + max(0, mid - a[i]) if su > intk: l = mid - 1 else: an...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMB...
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$ operatio...
n, m = [int(i) for i in input().split()] arr = [int(i) for i in input().split()] arr.sort() mid = n // 2 dp = [0] * n half = 0 for i in range(mid, n): if i == mid: dp[i] = arr[i] + m half += dp[i] else: dp[i] = arr[i] if dp[i] >= dp[i - 1]: break else: ...
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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN 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$ operatio...
def check(mid, k, n): cnt = 0 for i in range(n // 2, n): cnt += mid - ar[i] if cnt > k: return False if cnt <= k: return True else: return False def solve(n, k, ar): ar.sort() l = 1 h = 2000000000 while l != h: mid = (l + h + 1) // 2 ...
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 FUNC_DEF 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 VAR VAR N...
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$ operatio...
n_k = input() n_k = n_k.split() n = int(n_k[0]) k = int(n_k[1]) A = input() A = A.split() i = 0 while i < n: A[i] = int(A[i]) i = i + 1 A.sort() p = int(n / 2) i = 0 lim = int(n / 2) + 1 result = A[p] path = 0 while p < n: m = 1 while p + 1 < n and A[p + 1] == A[p]: p = p + 1 m = m + 1 ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP...
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$ operatio...
n = list(map(int, input().split())) in_arr = [int(x) for x in input().split()] in_arr.sort() arr = [] for i in range(int(n[0] / 2), n[0]): arr.append(in_arr[i]) l = 0 r = 10000000001 while r - l > 1: mid = int((r + l) / 2) total = 0 for i in arr: total += max(0, mid - i) if total <= n[1]: ...
ASSIGN VAR FUNC_CALL 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 LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBE...
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$ operatio...
n, k = map(int, input().split()) def find(m, k, a): for i in range(n): if k == 0: break if a[i] < m: temp = min(k, m - a[i]) a[i] += temp k -= temp else: break if a[0] == m: for i in range(1, n): if not a[i...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER RETURN NUMBER ASSIG...
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$ operatio...
n, k = map(int, input().split()) a = sorted(map(int, input().split())) if n == 1: print(a[0] + k) exit() y = n // 2 ans = a[y] while True: for y in range(y + 1, n): if a[y] != ans: break else: r = n - n // 2 ans += k // r print(ans) break r = y - 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 IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR WHILE NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR AS...
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$ operatio...
n, k = input().split() n = int(n) k = int(k) w = input().split() w = [int(i) for i in w] if n == 1: print(w[0] + k) else: w = sorted(w) idx = len(w) // 2 + 1 mul = 1 gain = 0 for i in range(idx - 1, len(w) - 1): d = w[i + 1] - w[i] if k > d * mul: k = k - d * mul ...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN 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$ operatio...
N, k = map(int, input().split()) a = list(map(int, input().split())) a = sorted(a) def calc(x): num = 0 for i in range(N // 2, N): num += max(x - a[i], 0) if num > k: return False return num <= k l, r = 0, 10**9 * 3 while r - l > 1: mid = (l + r) // 2 if calc(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 ASSIGN VAR FUNC_CALL 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 IF VAR VAR RETURN NUMBER RETURN VAR VAR ASSIGN VAR V...
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$ operatio...
n, k = map(int, input().split()) s = list(map(int, input().split())) s.sort() for i in range(n // 2, n - 1): if k >= (s[i + 1] - s[i]) * (i + 1 - n // 2): k -= (s[i + 1] - s[i]) * (i + 1 - n // 2) else: print(s[i] + k // (i + 1 - n // 2)) break else: print(s[-1] + k // (n - 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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR BIN...
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$ operatio...
n, k = map(int, input().split()) A = list(map(int, input().split())) A.sort() lena = len(A) medInd = lena // 2 res = A[medInd] count = 1 while k > 0: if count <= medInd: fin = A[medInd + count] if k < (fin - res) * count: res += k // count break else: 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 EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR BIN_OP BIN_OP 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$ operatio...
n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) low = a[n // 2] high = 2 * 10**9 + 5 def ok(x): r = 0 for i in range(n // 2, n): if a[i] < x: r += x - a[i] return r <= k while low + 1 < high: mid = (low + high) // 2 if ok(mid): low = mid ...
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 BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF 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$ operatio...
def cond(a, n, k, v): s = 0 for i in range(n // 2, n): s += max(0, v - a[i]) return s <= k def bin_search(a, n, k): left, right = -1, 10**18 while right - left > 1: mid = (right + left) // 2 if cond(a, n, k, mid): left = mid else: right = mid...
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 RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER 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 VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF 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$ operatio...
n, k = map(int, input().split()) ar = list(map(int, input().split())) ar.sort() med = ar[(n - 1) // 2] flag = True for i, j in enumerate(range((n + 1) // 2, n), 1): pr = ar[j] - ar[j - 1] if k >= pr * i: med = ar[j] k -= pr * i elif pr != 0: med = ar[j - 1] + k // i flag = Fa...
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 NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN 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$ operatio...
ans = 0 n, k = [int(x) for x in input().split()] a = [int(x) for x in input().split()] def binarysearch(l: int, r: int): global ans while l <= r: mid = (l + r) // 2 sum = 0 for i in range(n // 2, n): sum += max(0, mid - a[i]) if sum <= k: l = mid + 1 ...
ASSIGN VAR NUMBER 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 FUNC_DEF 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 VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR IF 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$ operatio...
n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() m = a[n // 2] p = 1 q = n // 2 + 1 e = True t = True if n == 1: m += k k = 0 q = 0 while a[q] == m: p += 1 q += 1 if q == n: q -= 1 e = False break if e == False: m += k // p k = 0 while...
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 ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN ...
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$ operatio...
n, k = tuple(map(int, input().split())) a = list(map(int, input().split())) a.sort() def ok(x): mv = int(0) for i in range(n // 2, n): if x - a[i] > 0: mv += x - a[i] if mv > k: return False if mv <= k: return True else: return False mx = 20000...
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 FUNC_DEF ASSIGN VAR FUNC_CALL 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 I...
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$ operatio...
import sys input = sys.stdin.readline N, K = map(int, sys.stdin.readline().split()) A = list(map(int, sys.stdin.readline().split())) A.sort() med = A[N // 2] n = K key = N // 2 num = 1 if N > 1: while key < N - 1 and n >= (A[key + 1] - A[key]) * num: med += A[key + 1] - A[key] n -= (A[key + 1] - A[...
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 ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP ...
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$ operatio...
n, m = map(int, input().split()) lis = sorted(map(int, input().split())) ind = n // 2 mid = lis[ind] i = ind + 1 c = 1 while m > 0 and i < n: k = lis[i] - mid if k == 0: c += 1 else: aa = min(m // c, k) m -= aa * c mid += aa c += 1 i += 1 mid += m // (ind + 1) pri...
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 VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL ...
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$ operatio...
n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) res = a[n // 2] for i in range(n // 2 + 1, n): d = min(a[i] - res, k // (i - n // 2)) res += d k -= d * (i - n // 2) res += k // (n // 2 + 1) print(res)
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 FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER 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$ operatio...
n, k = (int(i) for i in input().split()) a = sorted([int(i) for i in input().split()])[n // 2 :] m = 0 for i in range(n - n // 2): if i * (a[i] - m) <= k: k -= i * (a[i] - m) m = a[i] else: i -= 1 break if k // (i + 1) > 0: m += k // (i + 1) print(m)
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 BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR 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$ operatio...
n, k = map(int, input().split()) arr = list(map(int, input().split())) arr.sort() sum = 0 cnt = 0 ans = arr[n // 2] for i in range(n // 2, n): sum += arr[i] cnt += 1 check = (sum + k) // cnt if check >= arr[i] and i == n - 1: ans = max(ans, check) break if check >= arr[i] and check <...
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 VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF V...
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$ operatio...
n, k = map(int, input().split()) arr = list(map(int, input().split())) if n == 1: print(arr[0] + k) else: res = 0 arr.sort() a = arr[n // 2 :] diff = [] for i in range(1, len(a)): diff.append(a[i] - a[i - 1]) l = 0 while k > 0 and l < len(diff): if k > diff[l] * (l + 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 IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUN...
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$ operatio...
n, k = map(int, input().split()) array = list(map(int, input().split())) array.sort() med = n // 2 def key(m): s = 10**10 ind = None for i in range(n): if 0 <= m - array[i] <= s: s = m - array[i] ind = i if ind == None: return False if ind < med: ret...
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 BIN_OP NUMBER NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR IF NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR AS...
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$ operatio...
n, k = list(map(int, input().split())) a = list(map(int, input().split())) if n == 1: print(a[0] + k) exit(0) a = sorted(a) a = a[int(n / 2) :] + [10**10] n = int(n / 2) + 2 m, next = a[0], a[1] ans, nans = m, 1 while k > 0: dx = k / nans dy = next - ans if dx <= dy: ans = ans + dx b...
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 IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER LIST BIN_OP 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$ operatio...
def num_operations(daList, targetNum, numOpp): num = 0 for i in range(len(daList) // 2, len(daList)): num += (targetNum - daList[i]) * (daList[i] < targetNum) return num <= numOpp def binary_search(low, high, givenList, numOpp): res = low - 1 while low <= high: mid = (low + high) /...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN 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$ operatio...
import sys n, k = [int(x) for x in input().split()] lis = [int(x) for x in input().split()] lis = sorted(lis) middle_ind = n // 2 middle_value = lis[middle_ind] for i in range(middle_ind, n - 1): if k - (lis[i + 1] - lis[i]) * (i - middle_ind + 1) < 0: print(lis[i] + k // (i - middle_ind + 1)) sys....
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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VA...
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$ operatio...
def find(A, K): A = sorted(A) def findout(target, K): want = 0 for x in A: want += max(0, target - x) if want <= K: return True return False A = A[len(A) // 2 :] left = min(A) right = left + K + 1 while right - left > 1: mid = (le...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BI...
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$ operatio...
[n, k] = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() ps = [0] for i in range(n): ps.append(ps[-1] + a[i]) ans = 0 for i in range(n // 2, n): ts = ps[i + 1] - ps[n // 2] ts = ts + k avg = ts // (i - n // 2 + 1) try: if avg > a[i + 1]: continue ...
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 EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR AS...
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$ operatio...
n, k = map(int, input().split()) A = [int(x) for x in input().split()] A.sort() Fixed = n // 2 i = n // 2 + 1 if n == 1: print(A[0] + k) exit() if k - (i - Fixed) * (A[i] - A[Fixed]) < 0: print(A[Fixed] + k) exit() x = 0 while 1: if k - (i - Fixed) * (A[i] - A[Fixed]) < 0: x = k // (i - Fixe...
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 VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR IF BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_O...
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$ operatio...
valuenum, operationnum = [int(x) for x in input().split(" ")] values = [int(x) for x in input().split(" ")] values.sort() req = 0 lastmax = values[(valuenum - 1) // 2] canfill = True inclusions = 0 for i in range(1, (valuenum - 1) // 2 + 1): inclusions = i if values[(valuenum - 1) // 2 + i] > lastmax: i...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER 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$ operatio...
import sys def binary_search(start, end, array, n, k): solution = 0 while start <= end: med = (start + end) // 2 count = 0 for idx in range((n + 1) // 2 - 1, n): count += max(med - array[idx], 0) if count <= k: start = med + 1 solution = max(...
IMPORT FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUM...
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$ operatio...
n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() med = a[n // 2 :] i = 0 mn = med[0] for i in range(len(med) - 1): if k >= (i + 1) * (med[i + 1] - med[i]): k -= (i + 1) * (med[i + 1] - med[i]) mn = med[i + 1] else: mn += k // (i + 1) k = 0 bre...
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 ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR BIN_OP ...
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$ operatio...
n, k = map(int, input().split()) arr = [int(i) for i in input().split()] arr.sort() arr_size = len(arr) arr_start = int(arr_size / 2) if n == 1: flag = True else: flag = False m = 1 sum_k = 0 max_num = arr[arr_start] while arr_start < arr_size - 1: temp = arr[arr_start + 1] - arr[arr_start] sum_k = sum_...
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 FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE 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$ operatio...
class Read: @staticmethod def int(): return int(input()) @staticmethod def list(sep=" "): return input().split(sep) @staticmethod def list_int(sep=" "): return list(map(int, input().split(sep))) def solve(): n, k = Read.list_int() a = Read.list_int() a.so...
CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF STRING RETURN FUNC_CALL FUNC_CALL VAR VAR VAR FUNC_DEF STRING RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VA...
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$ operatio...
n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) s = [] med = a[n // 2] for i in range(n // 2): s.append((a[n // 2 + 1 + i] - a[n // 2 + i]) * (i + 1)) for i in range(n // 2): if k <= s[i]: med += k // (i + 1) k = 0 else: med = a[n // 2 + i + 1] k ...
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 LIST ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP BI...
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$ operatio...
n, k = map(int, input().split()) l = [int(x) for x in input().split()] l.sort() def bs(m): moves = abs(l[n // 2] - m) ma = m for i in range(n // 2 + 1, n): ma = max(l[i], ma) if l[i] < ma: moves += abs(l[i] - ma) if moves <= k: return True else: return F...
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 FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF 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$ operatio...
n, k = map(int, input().split()) a = sorted(map(int, input().split())) if n < 2: print(a[0] + k) exit() i = n // 2 while k >= (i - n // 2 + 1) * (a[i + 1] - a[i]): diff = (i - n // 2 + 1) * (a[i + 1] - a[i]) if diff: k -= diff a[n // 2 : i + 1] = [a[i + 1]] * (i - n // 2 + 1) i += 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 IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER 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$ operatio...
def do(arr, k): n = len(arr) arr = arr[n // 2 :] n -= n // 2 i = 0 while k and i < n - 1: while i < n - 1 and arr[i + 1] == arr[i]: i += 1 if i == n - 1: break if (arr[i + 1] - arr[i]) * (i + 1) <= k: k -= (arr[i + 1] - arr[i]) * (i + 1) ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN...
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$ operatio...
n, k = map(int, input().split()) x = sorted(map(int, input().split()))[n // 2 :] r = x[0] for i in range(1, len(x)): if i * (x[i] - r) <= k: k -= i * (x[i] - r) r = x[i] else: r += k // i break else: r += k // len(x) 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 BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR 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$ operatio...
n, k = list(map(int, input().split())) arr = list(map(int, input().split())) arr.sort() n //= 2 arr = arr[n:] n += 1 med = arr[0] flag = 1 while flag < n: if arr[flag] > med: kk = (arr[flag] - med) * flag if kk < k: k -= kk med = arr[flag] else: med += k /...
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 VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR V...
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$ operatio...
n, k = map(int, input().split()) l = [float("inf")] + sorted(map(int, input().split())) + [float("inf")] i = n // 2 + 2 I = (n + 1) // 2 cnt = 1 while k: while l[I] == l[i]: i += 1 cnt += 1 d = min((l[i] - l[I]) * cnt, k) l[I] += d // cnt k -= d print(l[I])
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST FUNC_CALL VAR STRING FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR WHILE VAR VAR VA...
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$ operatio...
l = [int(i) for i in input().split(" ")] n = l[0] k = l[1] l = [int(i) for i in input().split(" ")] l = sorted(l) med = (n - 1) // 2 val = l[med] end = False vl = 0 s = 1 vals = [] for i in range(med + 1, len(l)): if l[i] == l[i - 1]: s += 1 continue knum = s if k >= (l[i] - l[i - 1]) * s: ...
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASS...
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$ operatio...
def rint(): return int(input()) def rints(): return list(map(int, input().split())) n, k = rints() a = rints() a.sort() c = 1 m = a[n // 2] while c <= n // 2 and k > 0: ne = a[n // 2 + c] if (ne - m) * c > k: break k -= (ne - m) * c m = ne c += 1 print(m + k // c)
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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER V...
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$ operatio...
input1 = input() n, k = input1.split(" ") n = int(n) k = int(k) input2 = input() a = input2.split(" ") for t in range(n): a[t] = int(a[t]) if len(a) == 1: print(a[0] + k) else: a.sort() mid = int((n - 1) / 2) c = mid diff = [] if a[mid + 1] - a[mid] >= k: print(a[mid] + k) else: ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CA...
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$ operatio...
from itertools import accumulate n, k = map(int, input().split()) a = list(map(int, input().split())) if len(a) == 1: print(a[0] + k) else: a.sort() a = a[len(a) // 2 :] b = list(accumulate(a)) mx = 0 if a[0] + k <= a[1]: mx = a[0] + k for i in range(1, len(a) - 1): lmax = a...
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 FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR 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$ operatio...
n, k = map(int, input().strip().split()) l = list(map(int, input().strip().split())) l.sort() mid = int((n - 1) / 2) s = 0 mx = l[n - 1] ans = -1 def check(start, end, l): mx = l[end] ret = 0 for i in range(start, end): ret += mx - l[i] return ret for i in range(mid, n - 1): s += mx - l[...
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 FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR ASS...
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$ operatio...
n, k = [int(i) for i in input().split(" ")] a = [int(i) for i in input().split(" ")] a.sort() b = a[n // 2 :] def p(m): ans = 0 for s in b: if m <= s: break else: ans += m - s return ans <= k low = b[0] high = b[0] + k while low < high: mid = low + (high - low...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR RETURN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER V...
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$ operatio...
n, k = map(int, input().split()) mass = [int(i) for i in input().split()] mass.sort() mass = mass[(n - 1) // 2 :] lent = (n - 1) // 2 + 1 i = 0 num = 1 myx = mass[0] while k > 0: i += 1 if i == lent: myx += k // num break maxx = mass[i] k -= num * (maxx - myx) if k <= 0: k +=...
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 VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR NUMBER VAR NUMB...
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$ operatio...
def main(): n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() mid = n // 2 i = mid + 1 final_val = a[mid] while i < n and k > 0: if a[mid] != a[i]: if k >= (a[i] - a[mid]) * (i - mid): k -= (a[i] - a[mid]) * (i - mid) ...
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 BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR VAR NUMBER IF VAR VAR VAR VAR IF VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP 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$ operatio...
n, k = [int(s) for s in input().split()] arr = sorted([int(s) for s in input().split()]) arr = arr[::-1] arr = [pow(10, 11)] + arr[0 : n // 2 + 1] n = len(arr) point = n - 1 while k != 0: t = min(k, (n - point) * (arr[point - 1] - arr[point])) k -= t arr[point] += t // (n - point) if k != 0: poi...
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 VAR NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR NUMBER NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMB...
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$ operatio...
R = lambda: map(int, input().split()) n, k = R() L = sorted(R()) if n == 1: print(L[0] + k) quit() i = n // 2 m = L[i] s = 0 T = [0] i += 1 l = 0 while i < n: p = s t = L[i] - L[i - 1] s += t s += t * l T.append(s) i += 1 l += 1 j = 0 while j < len(T): if k < T[j]: break ...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE V...
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$ operatio...
n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() a.insert(0, 0) def F(m): s = 0 for i in range(n // 2 + 1, n + 1): s += max(0, m - a[i]) return s <= k l = a[n // 2 + 1] r = 100000000000 while l <= r: m = (l + r) // 2 if F(m): res = m l = 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 NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR R...
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$ operatio...
def bs(l, h): while l < h: m = (l + h + 1) // 2 if gf(m): l = m else: h = m - 1 return l def gf(x): s = 0 for i in a[m:]: s += max(0, x - i) return s <= k n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) m = n //...
FUNC_DEF 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 RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR F...
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$ operatio...
from sys import stdin n, k = (int(i) for i in stdin.readline().split()) arr = sorted(int(i) for i in stdin.readline().split()) bot = arr[n // 2] top = arr[-1] def double(alpha, beta): if beta == alpha + 1: if limit(beta) > k: return alpha else: return beta middle = (al...
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 VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_DEF IF VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR F...
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$ operatio...
from sys import stdin, stdout input = stdin.readline t = 1 for _ in range(t): n, k = map(int, input().split()) a = [int(x) for x in input().split()] a = sorted(a) val = 1 for i in range(n // 2 + 1, n): diff = (a[i] - a[i - 1]) * val if diff <= k: k -= diff else: ...
ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR 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 NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_O...
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$ operatio...
from sys import stdin, stdout def INI(): return int(stdin.readline()) def INL(): return [int(_) for _ in stdin.readline().split()] def INS(): return stdin.readline() def MOD(): return pow(10, 9) + 7 def OPS(ans): stdout.write(str(ans) + "\n") def OPL(ans): [stdout.write(str(_) + " ")...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING VAR VA...
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$ operatio...
n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() a = a + [a[n - 1]] c = 0 m = (n - 1) // 2 i = m if i + 1 < n: add = (a[i + 1] - a[i]) * (i - m + 1) while i + 1 < n and c + add <= k: c += add i += 1 add = (a[i + 1] - a[i]) * (i - m + 1) a[i] += (k - c) // (i - m + 1) print(a...
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 LIST VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VA...
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$ operatio...
from sys import stdin n, m = map(int, stdin.readline().strip().split()) s = list(map(int, stdin.readline().strip().split())) s.sort() s = s[n // 2 :] low = s[0] high = 2 * 10**9 def can(x): ans = 0 for i in range(len(s)): if s[i] < x: ans += x - s[i] if ans <= m: return True ...
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 VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CA...
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$ operatio...
n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() index = n >> 1 cur = a[index] i = index + 1 index = 1 while k > 0 and i < len(a): p = (a[i] - a[i - 1]) * index if k < index: break elif p <= k: cur = a[i] k = k - p index += 1 i += 1 el...
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 BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP...
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$ operatio...
n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) start_index = n // 2 cur_index = start_index m = a[start_index] numbers_to_inc_count = 1 while k != 0: if cur_index == n - 1: m += k // numbers_to_inc_count k = 0 elif (a[cur_index + 1] - m) * numbers_to_inc_count <= k:...
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 VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR B...
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$ operatio...
n, k = map(int, input().split()) a = [int(o) for o in input().split()] d = [] a = sorted(a) lol = n // 2 i = n // 2 cv = a[lol] while i < n: try: d.append([d[-1][0] + (a[i] - cv) * (i - lol), a[i], i]) except: d.append([(a[i] - cv) * (i - lol), a[i], i]) cv = a[i] if d[-1][0] > k: ...
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 LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER NUMBER BIN_OP 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$ operatio...
n, k = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() def check(m): c = 0 for i in range(n // 2, n): if a[i] > m: break else: c += m - a[i] return c <= k l = a[n // 2] r = a[n // 2] + k + 1 while r - l > 1: m = (r + l) // 2 if...
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 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 VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN...
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$ operatio...
n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() j = int(n / 2) x = 1 ans = a[j] while k > 0 and j < n - 1: y = a[j + 1] - a[j] if x * y <= k: k -= x * y x += 1 ans = a[j + 1] j += 1 else: ans += int(k / x) k = 0 break if 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 EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP ...
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$ operatio...
line1 = input().split() n, m = int(line1[0]), int(line1[1]) lst = input().split() lst = [int(x) for x in lst] lst.sort() median = n // 2 lst = lst[median:] total = [] for i in range(len(lst)): if i == 0: total.append(lst[i]) else: total.append(total[-1] + lst[i]) def eval(lst, total, index): ...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_C...
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$ operatio...
def check(x): ans1 = 0 for i in range(n // 2, n): ans1 += max(0, x - arr[i]) return ans1 n, k = map(int, input().split()) arr = list(map(int, input().split())) arr = sorted(arr) l = 1 r = 2000000000 ans = 0 while l <= r: mid = (l + r) // 2 if check(mid) <= k: ans = max(ans, mid) ...
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 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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIG...
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$ operatio...
n, k = map(int, input().split()) num = list(sorted(map(int, input().split()))) x1 = 1 x2 = 2000000000.0 + 1 while x1 <= x2: m = int((x1 + x2) / 2) s = 0 for i in range(int(n / 2), n): s += max(0, m - num[i]) if s <= k: ans = m x1 = m + 1 else: x2 = m - 1 print(ans)
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 ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP 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$ operatio...
def check(m): dif = lista[n // 2] + m soma = 0 for x in lista[n // 2 :]: soma += max(0, dif - x) return soma <= k n, k = [int(i) for i in input().split()] lista = [int(i) for i in input().split()] lista.sort() l = 0 r = 1000000001 while l < r: mid = (l + r + 1) // 2 if check(mid): ...
FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR RETURN 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 ASSIGN VAR NUMBER ASSIGN VA...
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$ operatio...
n, k = (*map(int, input().split()),) a = [int(x) for x in input().split()] a.sort() md = n // 2 wnl = 1 ub = a[md + wnl] if md + wnl < n else 10**10 v = a[md] while k: while md + wnl < n: if a[md + wnl] != v: break wnl += 1 ub = a[md + wnl] if md + wnl < n else 10**10 gp = ub - v...
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 VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR VAR WHILE VAR WHILE BIN_OP VAR VAR VAR IF VAR BIN_OP VA...
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$ operatio...
size, k = map(int, input().split()) array = sorted(list(map(int, input().split()))) median_pos = size // 2 increase_pos = list() dif = list() for x in range(median_pos + 1, size): cur = array[x] prev = array[x - 1] if cur != prev: increase_pos.append(x) dif.append(cur - prev) increased = 0 s...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF 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$ operatio...
import sys input = sys.stdin.readline n, k = list(map(int, input().split())) l = list(map(int, input().split())) l = sorted(l) p = n // 2 ans = l[p] tgt = 1 while p < n - 1: diff = l[p + 1] - l[p] if k >= diff * tgt: k -= diff * tgt p += 1 ans = l[p] tgt += 1 else: p...
IMPORT ASSIGN VAR 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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMB...
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$ operatio...
n, k = [int(i) for i in input().split()] a = sorted([int(i) for i in input().split()]) c = 1 ans = a[n // 2] for i in range(n // 2, n - 1): if a[i + 1] != a[i]: r = a[i + 1] - a[i] if k - c * r < 0: ans += k // c break k -= c * r ans += r c += 1 else: ...
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 NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VA...
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$ operatio...
mod = 1000000007 MOD = 998244353 ii = lambda: int(input()) si = lambda: input() dgl = lambda: list(map(int, input())) f = lambda: map(int, input().split()) il = lambda: list(map(int, input().split())) it = lambda: tuple(map(int, input().split())) ls = lambda: list(input()) n, k = f() diff = [] sm = 0 l = sorted(il()) i...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN 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 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$ operatio...
def can(x): cnt = 0 for i in range(n // 2, n): cnt += max(0, x - arr[i]) if cnt <= k: return True else: return False n, k = map(int, input().split()) arr = list(map(int, input().split())) arr.sort() if n == 1: print(arr[0] + k) else: l = arr[n // 2] r = arr[n // 2] ...
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 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...
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$ operatio...
n, k = map(int, input().split()) arr = sorted(list(map(int, input().split()))) mid = n // 2 q = 1 i = 0 ans = arr[mid] while mid + 1 < n: for i in arr[mid + 1 :]: if i != ans: break q += 1 mid += 1 if k - q * (i - ans) < 0: break k = k - q * (i - ans) ans = i ...
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 NUMBER ASSIGN VAR VAR VAR WHILE BIN_OP VAR NUMBER VAR FOR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF BIN_...
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$ operatio...
n, k = map(int, input().split()) lis = list(map(int, input().split())) lis.sort() mid = len(lis) // 2 c = 0 i = 1 ans = lis[mid] while i < n - mid: l = lis[mid + i] - ans if k - c >= l * i: c += l * i ans += l else: ans += (k - c) // i c = k break i += 1 if c < 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 EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR IF BIN_OP 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$ operatio...
n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() def f(m, k, n, a): j = n // 2 g = a[j] if m - g > 0: k -= m - g for i in range(j + 1, n): if a[i] <= m: k -= m - a[i] return k >= 0 l = a[0] r = a[-1] + k + 1 while r - l > 1: m = (l + 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 EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR BIN_OP VAR VA...
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$ operatio...
n, k = map(int, input().split()) l = list(map(int, input().split())) l.sort() lo, hi = 1, 999999999999 while lo < hi: mid = (lo + hi) // 2 tmp = 0 for i in range(n // 2, n): tmp += max(mid - l[i], 0) if tmp <= k: lo = mid else: hi = mid - 1 if hi - lo == 1: tmp = ...
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 NUMBER 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 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$ operatio...
def main(): n, k = input().split() n = int(n) k = int(k) a = [int(i) for i in input().split()] a.sort() mid = int(n / 2) for i in range(mid + 1, n): if a[mid] < a[i]: diff = a[i] - a[mid] if (i - mid) * diff >= k: print(a[mid] + int(k / (i - mi...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VA...
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$ operatio...
x = input().split() n = input().split() for i in range(0, len(n)): n[i] = int(n[i]) moves = int(x[1]) n.sort() medianIndex = int(len(n) / 2) median = n[medianIndex] maxi = int(n[-1]) + moves medmid = 0 tots = 0 while median <= maxi: medmid = int((median + maxi) / 2) total = 0 for i in range(medianIndex,...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP 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$ operatio...
def isPossible(x, k): temp = a.copy() for i in range(int(n / 2), n): if x > temp[i]: diff = x - temp[i] k -= diff temp[i] = x if temp[i] < temp[i - 1] or k < 0: return False else: break return True n, k = map(int, ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FU...
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$ operatio...
N, K = map(int, input().split()) A = list(map(int, input().split())) piv = N // 2 A.sort() ans = A[piv] k = 0 for i in range(piv + 1, N): if ans < A[i]: a = (A[i] - ans) * (i - piv) if k + a > K: ans += (K - k) // (i - piv) k += a break else: a...
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 ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR ...