AtCoder Beginner Contest 144 - Gluttony

Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i.
In the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i. The details of the contest are as follows:
 - A team should assign one member to each food, and should not assign the same member to multiple foods.
 - It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish.
 - The score of a team is the longest time it takes for an individual member to finish the food.
Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total.
What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally?

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N \leq 2 \times 10^5
 - 0 \leq K \leq 10^{18}
 - 1 \leq A_i \leq 10^6\ (1 \leq i \leq N)
 - 1 \leq F_i \leq 10^6\ (1 \leq i \leq N)

-----Input-----
Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N
F_1 F_2 ... F_N

-----Output-----
Print the minimum possible score of the team.

-----Sample Input-----
3 5
4 2 1
2 3 1

-----Sample Output-----
2

They can achieve the score of 2, as follows:
 - Member 1 does 4 sets of training and eats Food 2 in (4-4) \times 3 = 0 seconds.
 - Member 2 does 1 set of training and eats Food 3 in (2-1) \times 1 = 1 second.
 - Member 3 does 0 sets of training and eats Food 1 in (1-0) \times 2 = 2 seconds.
They cannot achieve a score of less than 2, so the answer is 2.

Difficulty: MEDIUM

Starter code:

Solutions:
(n, k) = map(int, input().split())
a = sorted(list(map(int, input().split())))
f = sorted(list(map(int, input().split())))[::-1]
r = 10 ** 12 + 1
l = -1
while r - l > 1:
	s = k
	mid = (r + l) // 2
	for (i, j) in zip(a, f):
		if mid < i * j:
			s -= i - mid // j
	if s < 0:
		l = mid
	else:
		r = mid
print(r)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)

def is_ok(x):
	c = 0
	for (a, f) in zip(A, F):
		c += max(0, a - x // f)
	if c <= k:
		return True
	else:
		return False
ng = -1
ok = 10 ** 18
while ng + 1 < ok:
	c = (ng + ok) // 2
	if is_ok(c):
		ok = c
	else:
		ng = c
print(ok)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
if sum(A) <= K:
	print(0)
	exit()
A.sort()
F.sort(reverse=True)

def check(x):
	k = 0
	for (a, f) in zip(A, F):
		k += max(0, a - x // f)
	return k <= K
(ng, ok) = (0, 10 ** 18 + 1)
while ok - ng > 1:
	x = (ok + ng) // 2
	if check(x):
		ok = x
	else:
		ng = x
print(ok)


import numpy as np

def is_ok(mid, k):
	s = np.maximum(a - mid // f, 0).sum()
	if s <= k:
		return True
	else:
		return False
(n, k) = map(int, input().split())
a = np.array(list(map(int, input().split())))
f = np.array(list(map(int, input().split())))
a = np.sort(a)
f = np.sort(f)[::-1]
(l, r) = (-1, np.max(a * f))
while l + 1 < r:
	mid = (l + r) // 2
	if is_ok(mid, k):
		r = mid
	else:
		l = mid
print(r)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
r = 1000000000000.0 + 1
l = -1

def ok(c):
	s = 0
	for i in range(N):
		s += max(0, A[i] - c // F[i])
	return bool(s <= K)
while l + 1 < r:
	c = (l + r) // 2
	a = ok(c)
	if a == True:
		r = c
	else:
		l = c
print(int(r))


import sys
(n, k) = map(int, input().split())
a = sorted(list(map(int, input().split())))
f = sorted(list(map(int, input().split())), reverse=True)
(h, l) = (max((a[i] * f[i] for i in range(n))) + 1, 0)
if sum(a) <= k:
	print(0)
	sys.exit()
while h - l > 1:
	m = (h + l) // 2
	practice = sum((max(0, a[i] - m // f[i]) for i in range(n)))
	if practice <= k:
		h = m
	else:
		l = m
print(h)


(n, k) = map(int, input().split())
a = sorted(list(map(int, input().split())))
f = sorted(list(map(int, input().split())))[::-1]
(l, r) = (-1, 10 ** 12)
while r - l > 1:
	x = (r + l) // 2
	res = 0
	for i in range(n):
		res += max(0, a[i] - x // f[i])
	if res > k:
		l = x
	else:
		r = x
print(r)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
import numpy as np
a = np.array(a)
f = np.array(f)
low = -1
hi = 10 ** 18
while hi - low > 1:
	ave = (hi + low) // 2
	if np.maximum(0, a - ave // f).sum() <= k:
		hi = ave
	else:
		low = ave
print(hi)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort()
f.reverse()
(l, r) = (-1, 10 ** 12)
while r - l != 1:
	t = (l + r) // 2
	c = 0
	for i in range(n):
		c += max(a[i] - t // f[i], 0)
	if c <= k:
		r = t
	else:
		l = t
print(r)


(n, k) = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())))[::-1]

def is_time(x):
	c = 0
	for i in range(n):
		c += max(0, A[i] - x // F[i])
	if c <= k:
		return True
	return False
ng = -1
ok = 0
for i in range(n):
	ok = max(ok, A[i] * F[i])
while ok - ng > 1:
	m = (ng + ok) // 2
	if is_time(m):
		ok = m
	else:
		ng = m
print(ok)


import sys
readline = sys.stdin.readline
(N, K) = map(int, readline().split())
A = list(map(int, readline().split()))
F = list(map(int, readline().split()))
A.sort()
F.sort(reverse=True)
ng = -1
ok = 10 ** 12 + 100
while ok - ng > 1:
	mid = (ok + ng) // 2
	if sum((max(0, a - mid // f) for (a, f) in zip(A, F))) <= K:
		ok = mid
	else:
		ng = mid
print(ok)


import numpy as np

def bin_search(left, right, check):
	while left + 1 < right:
		middle = left + right >> 1
		if check(middle):
			right = middle
		else:
			left = middle
	return right

def check(m):
	return np.maximum(A - m // F, Z).sum() <= K
(N, K) = map(int, input().split())
A = np.array(input().split(), dtype=np.int32)
F = np.array(input().split(), dtype=np.int32)
Z = np.zeros((N,), dtype=np.int32)
A.sort()
F = F[np.argsort(-F)]
print(bin_search(-1, 10 ** 12, check))


import math
(N, K) = map(int, input().split())
X = [(b, a * b) for (a, b) in zip(sorted(list(map(int, input().split()))), sorted(list(map(int, input().split())))[::-1])]
(min_i, max_i, index) = (0, 10 ** 12, 1)
while True:
	(index, max_i, min_i) = ((index - 1 + min_i) // 2, index - 1, min_i) if sum((math.ceil(max(0, c - index) / b) for (b, c) in X)) <= K else ((index + 1 + max_i) // 2, max_i, index + 1)
	if min_i > max_i:
		print(min_i)
		break


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)

def is_ok(x):
	tmp = 0
	for (a, f) in zip(A, F):
		y = a * f
		if y > x:
			tmp += a - x // f
	return tmp <= k
ok = 10 ** 16
ng = -1
while ok - ng > 1:
	mid = (ok + ng) // 2
	if is_ok(mid):
		ok = mid
	else:
		ng = mid
print(ok)


import numpy as np
(n, k) = map(int, input().split())
a = np.array(list(map(int, input().split())))
f = np.array(list(map(int, input().split())))
a.sort()
f.sort()
f = f[::-1]

def test(x):
	return np.maximum(0, a - x // f).sum() <= k

def nibutan(low, hi):
	while True:
		ave = (low + hi) // 2
		if test(ave):
			hi = ave
		else:
			low = ave
		if hi - low == 1:
			break
	li = [low, hi]
	return li
li = nibutan(-1, 10 ** 12)
print(li[1])


import bisect
(n, k) = map(int, input().split())
a = sorted(list(map(int, input().split())))[::-1]
b = sorted(list(map(int, input().split())))
ma = a[0] * b[-1]
mi = 0
if sum(a) < k + 1:
	ma = 0
for i in range(n):
	a[i] = a[i] * b[i]
while abs(ma - mi) > 1:
	now = 0
	for i in range(n):
		now += max(0, (a[i] - (mi + ma) // 2 + b[i] - 1) // b[i])
	if now > k:
		mi = (ma + mi) // 2
	else:
		ma = (ma + mi) // 2
print(ma)


import sys
input = sys.stdin.readline
(N, K) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort(reverse=True)

def check(x):
	k = K
	for i in range(N):
		if a[i] * b[i] > x:
			k += (x - a[i] * b[i]) // b[i]
	return k >= 0
ok = 10 ** 12
ng = -1
while ok - ng > 1:
	m = (ok + ng) // 2
	if check(m):
		ok = m
	else:
		ng = m
print(ok)


import numpy as np
(N, K) = map(int, input().split())
A = [int(c) for c in input().split()]
F = [int(c) for c in input().split()]
A.sort()
F.sort(reverse=True)
A = np.array(A)
F = np.array(F)
Asum = A.sum()
M = np.max(A * F)
l = -1
r = M + 1
while l + 1 < r:
	s = (l + r) // 2
	cnt = Asum - np.minimum(A, s // F).sum()
	if cnt > K:
		l = s
	else:
		r = s
print(r)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort(reverse=True)
F.sort()

def ok(x):
	tot = 0
	for i in range(n):
		tot += max(0, A[i] - x // F[i])
	if tot <= k:
		return True
	else:
		return False
l = -1
r = 10 ** 18
while l + 1 < r:
	c = (l + r) // 2
	if ok(c):
		r = c
	else:
		l = c
print(r)


import sys
input = sys.stdin.readline
import numpy as np

def main():
	(n, k) = list(map(int, input().split()))
	A = np.array(sorted(list(map(int, input().split()))))
	F = np.array(sorted(list(map(int, input().split())), reverse=True))

	def is_time(x):
		c = np.maximum(A - x // F, 0).sum()
		if c <= k:
			return True
		return False
	ng = -1
	ok = max(A * F)
	while ok - ng > 1:
		m = (ng + ok) // 2
		if is_time(m):
			ok = m
		else:
			ng = m
	print(ok)

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)

def ok(v):
	return sum([max(0, (a[i] * f[i] - v + (f[i] - 1)) // f[i]) for i in range(n)]) <= k
if ok(0):
	print(0)
	exit()
mi = 0
ma = 10 ** 12
while mi + 1 < ma:
	m = (mi + ma) // 2
	if ok(m):
		ma = m
	else:
		mi = m
print(ma)


def main():
	import numpy as np
	import sys
	input = sys.stdin.readline
	(N, K) = list(map(int, input().split()))
	A = np.sort(list(map(int, input().split())))
	F = np.sort(list(map(int, input().split())))[::-1]
	if K >= np.sum(A) * N:
		print(0)
		return
	ma = A[-1] * F[0]
	mi = 0
	A = A * F
	while ma != mi:
		tgt = (ma + mi) // 2
		tmp = np.ceil((A - tgt) / F)
		if np.sum(tmp[tmp > 0]) <= K:
			ma = (ma + mi) // 2
		else:
			mi = (ma + mi) // 2 + 1
	print(ma)

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
a = sorted(map(int, input().split()))[::-1]
f = sorted(map(int, input().split()))

def check(x):
	res = 0
	for i in range(n):
		res += (max(0, a[i] * f[i] - x) + f[i] - 1) // f[i]
	return res
ok = 10 ** 12
ng = -1
while ok - ng > 1:
	m = (ok + ng) // 2
	res = check(m)
	if res <= k:
		ok = m
	else:
		ng = m
print(ok)


((_, K), *T) = [map(int, t.split()) for t in open(0)]
(A, B) = map(sorted, T)
(m, M, i) = (0, 2 ** 40, 1)
exec('i,M,m=((i+m)//2,i,m) if -sum(min(0,i-a*b)//b for a,b in zip(A,B[::-1]))<=K else((i+M)//2,M,i);' * 41)
print(M)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a = sorted(a)
f = sorted(f, reverse=True)

def is_lessthanK(X):
	ans = 0
	for (A, F) in zip(a, f):
		if A * F > X:
			ans += A - X // F
		if ans > k:
			return False
	return True
ng = -1
ok = a[-1] * f[0]
while ok - ng > 1:
	mid = (ok + ng) // 2
	if is_lessthanK(mid):
		ok = mid
	else:
		ng = mid
print(ok)


import numpy as np

def is_ok(mid, K, A, F):
	return np.maximum(A - mid // F, 0).sum() <= K

def main():
	(N, K) = input_line(int, int)
	A = input_line([int])
	F = input_line([int])
	A = np.array(sorted(A))
	F = np.array(sorted(F, reverse=True))
	ng = -1
	ok = int(1000000000000.0)
	while ok - ng > 1:
		mid = (ng + ok) // 2
		if is_ok(mid, K, A, F):
			ok = mid
		else:
			ng = mid
	print(ok)

def input_line(*types):
	if isinstance(types[0], list):
		return [types[0][0](x) for x in input().split()]
	elif len(types) == 1:
		return types[0](input())
	else:
		return [t(x) for (t, x) in zip(types, input().split())]

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
ok = 10 ** 15
ng = -1
while ok - ng > 1:
	check = (ok + ng) // 2
	cnt = 0
	for i in range(n):
		cnt += max(0, a[i] - check // f[i])
	if cnt > k:
		ng = (ok + ng) // 2
	else:
		ok = (ok + ng) // 2
print(ok)


import numpy as np

def main():
	(n, k) = map(int, input().split())
	a = np.array(list(map(int, input().split())), dtype=np.int64)
	f = np.array(list(map(int, input().split())), dtype=np.int64)
	a = np.sort(a)
	f = np.sort(f)[::-1]
	(l, r) = (0, 10 ** 12)
	while l <= r:
		m = (l + r) // 2
		tr = np.clip(a - m // f, 0, None).sum()
		if tr > k:
			l = m + 1
		else:
			r = m - 1
	print(l)

def __starting_point():
	main()
__starting_point()


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort(reverse=True)
F.sort()
U = 10 ** 12
L = -1
while U - L > 1:
	x = (U + L) // 2
	cnt = 0
	for i in range(N):
		if x // F[i] < A[i]:
			cnt += A[i] - x // F[i]
	if cnt > K:
		L = x
	else:
		U = x
print(U)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
(left, right) = (-1, a[-1] * f[0])
while right - left > 1:
	mid = (left + right) // 2
	ck = 0
	for i in range(n):
		ck += max(0, a[i] - mid // f[i])
	if ck <= k:
		right = mid
	else:
		left = mid
print(right)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
ng = -1
ok = 10 ** 12
while ok - ng > 1:
	mid = (ok + ng) // 2
	cnt = 0
	for (i, e) in enumerate(a):
		cnt += max(0, e - mid // f[i])
	if cnt <= k:
		ok = mid
	else:
		ng = mid
print(ok)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
l = -1
r = 10 ** 13
while r - l != 1:
	m = (l + r) // 2
	x = 0
	for i in range(N):
		x += max(0, A[i] - m // F[i])
	if x <= K:
		r = m
	else:
		l = m
print(r)


import sys
readline = sys.stdin.readline
import numpy as np
(N, K) = map(int, readline().split())
A = np.array(sorted(list(map(int, readline().split()))))
F = np.array(sorted(list(map(int, readline().split())), reverse=True))
ok = A[-1] * F[0]
ng = -1

def isOk(x):
	return A.sum() - np.minimum(A, x // F).sum() <= K
while ok - ng > 1:
	mid = (ok + ng) // 2
	if isOk(mid):
		ok = mid
	else:
		ng = mid
print(ok)


(N, K) = map(int, input().split())
A = sorted(map(int, input().split()))
F = sorted(map(int, input().split()), reverse=True)
l = -1
r = A[-1] * F[0]
while l + 1 < r:
	x = (l + r) // 2
	cnt = 0
	for i in range(N):
		cnt += max(A[i] - x // F[i], 0)
	if cnt <= K:
		r = x
	else:
		l = x
print(r)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
mx = max(a) * max(f)
mn = -1
while mx - mn > 1:
	mid = (mx + mn) // 2
	shugyo = 0
	for i in range(n):
		a_ = mid // f[i]
		shugyo += max(a[i] - a_, 0)
	if shugyo <= k:
		mx = mid
	else:
		mn = mid
print(mx)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
F.sort()
A.sort(reverse=True)

def func(X):
	s = 0
	for i in range(N):
		(a, f) = (A[i], F[i])
		s += max(0, a - X // f)
	return s <= K
R = 10 ** 12
L = -1
while R - L > 1:
	m = (R + L) // 2
	if func(m):
		R = m
	else:
		L = m
print(R)


from math import ceil
(n, k) = map(int, input().split())
a = sorted(list(map(int, input().split())))
f = sorted(list(map(int, input().split())), reverse=True)
l = []
for i in range(n):
	l.append([f[i] * a[i], a[i], f[i]])
l.sort()
ng = -1
ok = l[n - 1][0]
while ok - ng > 1:
	mid = (ok + ng) // 2
	cnt = 0
	for i in range(n):
		if l[i][0] > mid:
			cnt += ceil((l[i][0] - mid) / l[i][2])
	if cnt <= k:
		ok = mid
	else:
		ng = mid
print(ok)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A = sorted(A)
F = sorted(F)[::-1]
import numpy as np
a = np.array(A)
f = np.array(F)
low = -1
high = 10 ** 18
while high - low > 1:
	d = (high + low) // 2
	if np.maximum(0, a - d // f).sum() <= K:
		high = d
	else:
		low = d
print(high)


def abc144_e():
	import numpy as np
	(N, K) = map(int, input().split())
	A = np.array(input().split(), dtype=np.int64)
	F = np.array(input().split(), dtype=np.int64)
	A = np.sort(A)
	F = np.sort(F)[::-1]
	low = -1
	up = 10 ** 12
	while up - low > 1:
		v = (up + low) // 2
		x = A - v // F
		if x[x > 0].sum() > K:
			low = v
		else:
			up = v
	print(up)

def __starting_point():
	abc144_e()
__starting_point()


(N, K) = map(int, input().split())
(*A,) = map(int, input().split())
(*F,) = map(int, input().split())
A.sort()
F.sort(reverse=True)

def f(x):
	ans = 0
	for (i, j) in zip(A, F):
		ans += (i * j - x + j - 1) // j if i * j - x >= 0 else 0
	return ans <= K
(l, r) = (-1, 10 ** 18 + 1)
while r - l > 1:
	mid = (r + l) // 2
	if f(mid):
		r = mid
	else:
		l = mid
print(r)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
pi = [a[i] * f[i] for i in range(n)]
l = -1
r = max(pi)
while l + 1 < r:
	x = (l + r) // 2
	s = sum([max(a[i] - x // f[i], 0) for i in range(n)])
	if s <= k:
		r = x
	else:
		l = x
print(r)


import math
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
if sum(A) <= K:
	print(0)
	exit()
A.sort()
F.sort(reverse=True)
(l, r) = (-1, 10 ** 12 + 1)
while r - l > 1:
	m = (l + r) // 2
	k = 0
	for i in range(N):
		(a, f) = (A[i], F[i])
		k += max(0, a - m // f)
	if k <= K:
		r = m
	else:
		l = m
print(r)


(n, k) = map(int, input().split())
arr1 = list(map(int, input().split()))
arr1 = sorted(arr1)
arr2 = list(map(int, input().split()))
arr2 = sorted(arr2, reverse=True)
l = -1
r = 10 ** 12 + 1
while r - l != 1:
	m = (r + l) // 2
	tmp = 0
	for i in range(n):
		if arr1[i] > m // arr2[i]:
			tmp += arr1[i] - m // arr2[i]
	if tmp <= k:
		r = m
	else:
		l = m
print(r)


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
a = sorted(list(map(int, input().split())))
f = sorted(list(map(int, input().split())), reverse=True)
lft = -1
rgt = 10 ** 12
while rgt - lft > 1:
	mid = (rgt + lft) // 2
	cnt = 0
	for (i, e) in enumerate(a):
		cnt += max(0, e - mid // f[i])
	if cnt <= k:
		rgt = mid
	else:
		lft = mid
print(rgt)


(n, k) = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())))[::-1]
o = []
for (a, f) in zip(A, F):
	o.append(a * f)
ok = max(o)
ng = -1
while ok - ng > 1:
	mid = (ok + ng) // 2
	k1 = 0
	for i in range(n):
		k1 += max(0, A[i] - mid // F[i])
	if k1 <= k:
		ok = mid
	else:
		ng = mid
print(ok)


import numpy as np
(a, b) = map(int, input().split())
A = np.array(sorted(list(map(int, input().split()))))
F = np.array(sorted(list(map(int, input().split())), reverse=True))
s = A.sum()
x = -1
y = 10 ** 12
while x + 1 < y:
	mid = (x + y) // 2
	if s - np.minimum(A, mid // F).sum() <= b:
		y = mid
	else:
		x = mid
print(y)


def main():
	import sys
	input = sys.stdin.readline
	import numpy as np
	(n, k) = list(map(int, input().split()))
	A = np.array(input().split(), dtype=np.int64)
	F = np.array(input().split(), dtype=np.int64)
	A.sort()
	F.sort()
	F = F[::-1]

	def ok(x):
		cnt = np.maximum(0, A - x // F).sum()
		return cnt <= k
	l = -1
	r = 10 ** 12 + 1
	while r - l > 1:
		mid = (r + l) // 2
		if ok(mid):
			r = mid
		else:
			l = mid
	print(r)

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort()
f.reverse()
li = [0] * n
for i in range(n):
	li[i] = a[i] * f[i]
l = -1
r = 10 ** 18 + 5
while l + 1 < r:
	m = (l + r) // 2
	cnt = 0
	for i in range(n):
		ov = li[i] - m
		if ov > 0:
			cnt += (ov + f[i] - 1) // f[i]
	if cnt <= k:
		r = m
	else:
		l = m
print(r)


import numpy as np
(n, k) = list(map(int, input().split()))
A = np.array(input().split(), np.int)
F = np.array(input().split(), np.int)
A.sort()
F.sort()
F = F[::-1]
left = -1
right = (A * F).sum()
while right - left > 1:
	split_line = (left + right) // 2
	r = np.maximum(0, A - split_line // F).sum() <= k
	if r:
		right = split_line
	else:
		left = split_line
print(right)


import numpy as np
(N, K) = map(int, input().split())
As = np.array(sorted(map(int, input().split())))
Fs = np.array(sorted(map(int, input().split()), reverse=True))
times = As * Fs
ng = -1
ok = np.amax(times) + 1
while abs(ok - ng) > 1:
	mid = (ok + ng) // 2
	k = np.sum(np.maximum(np.ceil((times - mid) / Fs), 0))
	if k > K:
		ng = mid
	else:
		ok = mid
print(ok)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort(reverse=True)
f.sort()
top = 10 ** 13
bot = -1

def ok(x):
	res = 0
	for i in range(n):
		res += max(0, a[i] - x // f[i])
	return res <= k
while top - bot > 1:
	mid = (top + bot) // 2
	if ok(mid):
		top = mid
	else:
		bot = mid
print(top)


import numpy as np

def solve(n, k, aaa, fff):
	aaa = np.sort(aaa)
	fff = np.sort(fff)[::-1]
	l = -1
	r = 1000000000000.0
	while l + 1 < r:
		c = (l + r) // 2
		s = np.clip(aaa - c // fff, 0, None).sum()
		if s <= k:
			r = c
		else:
			l = c
	return int(r)
(n, k) = map(int, input().split())
aaa = np.array(list(map(int, input().split())), dtype=np.int64)
fff = np.array(list(map(int, input().split())), dtype=np.int64)
print(solve(n, k, aaa, fff))


(N, K) = map(int, input().split())
X = [(b, a * b) for (a, b) in zip(sorted(list(map(int, input().split()))), sorted(list(map(int, input().split())))[::-1])]
(m, M, i) = (0, 2 ** 40, 1)
exec('i,M,m=((i+m)//2,i,m) if -sum(min(0,i-c)//b for b, c in X)<=K else((i+M)//2,M,i);' * 50)
print(M)


import numpy as np
(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
a.sort()
f.sort(reverse=True)
a = np.array(a)
f = np.array(f)
s = a.sum()
(l, u) = (-1, f[0] * a[-1])
while l + 1 < u:
	m = (l + u) // 2
	if s - np.minimum(a, m // f).sum() <= k:
		u = m
	else:
		l = m
print(u)


(N, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
l = -1
r = 10 ** 12

def ok(c):
	s = 0
	for (a, f) in zip(A, F):
		s += max(0, a - c // f)
	return s <= K
while r - l > 1:
	c = (l + r) // 2
	if ok(c):
		r = c
	else:
		l = c
print(r)


import numpy as np
(n, k) = list(map(int, input().split()))
a = np.array(input().split(), dtype=int)
f = np.array(input().split(), dtype=int)
a = np.sort(a)[::-1]
f = np.sort(f)
ok = 10 ** 18
ng = -1
import math

def isOK(val, arr, farr, k):
	return arr.sum() - np.minimum(arr, val // farr).sum() <= k
while abs(ok - ng) > 1:
	mid = abs(ok + ng) // 2
	if isOK(mid, a, f, k):
		ok = mid
	else:
		ng = mid
print(ok)


def is_ok(x):
	result = 0
	for i in range(N):
		a = A[i]
		t = x // F[i]
		if t < a:
			result += a - t
	return result <= K
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
ok = A[-1] * F[0]
ng = -1
while ng + 1 < ok:
	c = ng + (ok - ng) // 2
	if is_ok(c):
		ok = c
	else:
		ng = c
print(ok)


import numpy as np

def resolve():

	def check(X):
		a = X // F
		diff = np.maximum(A - a, 0)
		cnt = np.sum(diff)
		return cnt <= K
	(N, K) = list(map(int, input().split()))
	A = np.array(input().split(), np.int64)
	F = np.array(input().split(), np.int64)
	A.sort()
	F.sort()
	F = F[::-1]
	ok = 10 ** 12
	ng = -1
	while ok - ng > 1:
		X = (ok + ng) // 2
		if check(X):
			ok = X
		else:
			ng = X
	print(ok)

def __starting_point():
	resolve()
__starting_point()


def main():
	(n, k, *a) = map(int, open(0).read().split())
	(a, f) = (sorted(a[:n])[::-1], sorted(a[n:]))
	ok = 10 ** 12
	ng = -1
	while abs(ok - ng) > 1:
		mid = (ok + ng) // 2
		l = k
		for (b, g) in zip(a, f):
			if b * g > mid:
				l -= b - mid // g
		if l < 0:
			ng = mid
		else:
			ok = mid
	print(ok)
main()


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]
a.sort()
f.sort(reverse=True)
mi = 0
ma = max([i * j for (i, j) in zip(a, f)])
while mi != ma:
	b = (mi + ma) // 2
	cost = 0
	for (i, j) in zip(a, f):
		cost += max(0, i - b // j)
	if cost <= k:
		ma = b
	else:
		mi = b + 1
print(mi)


import numpy as np

def main():
	(N, K) = list(map(int, input().split()))
	A = np.array(list(map(int, input().split())))
	F = np.array(list(map(int, input().split())))
	A.sort()
	F = np.sort(F)[::-1]
	time = A * F
	high = 10 ** 12 + 1
	low = -1
	while high - low > 1:
		middle = (high + low) // 2
		temp = np.where(time > middle, time - middle, 0)
		temp = np.ceil(temp / F).sum()
		if temp <= K:
			high = middle
		else:
			low = middle
	middle = high
	temp = np.where(time > middle, time - middle, 0)
	temp = np.ceil(temp / F)
	time = (time - temp * F).max()
	print(int(time))

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
ok = max(a) * max(f)
ng = -1
while ok - ng > 1:
	mid = (ok + ng) // 2
	t = 0
	for i in range(n):
		t += max(0, a[i] - int(mid / f[i]))
	if t > k:
		ng = mid
	else:
		ok = mid
print(ok)


import math
(N, K) = map(int, input().split())
X = [(b, a * b) for (a, b) in zip(sorted(list(map(int, input().split()))), sorted(list(map(int, input().split())))[::-1])]
(m, M, i) = (0, 10 ** 12, 1)
exec('i,M,m=((i+m)//2,i,m) if sum(math.ceil(max(0,c-i)/b)for b, c in X)<=K else((i+M)//2,M,i);' * 50)
print(M)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort(reverse=True)
F.sort()
ng = -1
ok = 10 ** 12
while ok - ng > 1:
	mid = (ok + ng) // 2
	temp = 0
	flag = 0
	for i in range(n):
		a = mid // F[i]
		if a > A[i]:
			continue
		else:
			temp += A[i] - a
	if temp > k:
		flag = 1
	if flag:
		ng = mid
	else:
		ok = mid
print(ok)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
l = -1
r = 10 ** 13
while r - l > 1:
	m = (l + r) // 2
	if sum([a - m // f if a * f > m else 0 for (a, f) in zip(A, F)]) <= k:
		r = m
	else:
		l = m
print(r)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort()
f.reverse()
l = -1
r = max(a) * max(f) + 1
sum = sum(a)
while abs(l - r) > 1:
	x = (l + r) // 2
	ct = 0
	for i in range(n):
		ct += max(a[i] - x // f[i], 0)
	if ct <= k:
		r = x
	else:
		l = x
print(r)


import sys
import numpy as np
readline = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
mod = 10 ** 9 + 7
INF = 10 ** 18
eps = 10 ** (-7)
(n, k) = map(int, input().split())
a = np.array(readline().split(), np.int64)
f = np.array(readline().split(), np.int64)
a.sort()
f.sort()
f = f[::-1]

def test(x):
	return np.maximum(0, a - x // f).sum() <= k
l = -1
r = INF
while l + 1 < r:
	mid = (l + r) // 2
	if test(mid):
		r = mid
	else:
		l = mid
print(r)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
L = -1
R = 10 ** 12 + 1
while R - L > 1:
	Mid = (L + R) // 2
	tmp = 0
	for (a, f) in zip(A, F):
		tmp += max(0, a - Mid // f)
	if tmp <= K:
		R = Mid
	else:
		L = Mid
print(R)


(n, k) = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()
F = [int(i) for i in input().split()]
F.sort(reverse=True)
left = -1
right = 10 ** 12

def f(x):
	return sum((max(A[i] - x // F[i], 0) for i in range(n))) <= k
while right - left > 1:
	mid = (left + right) // 2
	if f(mid):
		right = mid
	else:
		left = mid
print(right)


(N, K) = map(int, input().split())
import numpy as np
A = np.array(input().split(), np.int64)
B = np.array(input().split(), np.int64)
A.sort()
B.sort()
B = B[::-1]
right = max(A * B)
left = -1

def test(t):
	C = A - t // B
	D = np.where(C < 0, 0, C)
	return D.sum() <= K
while left + 1 < right:
	mid = (left + right) // 2
	if test(mid):
		right = mid
	else:
		left = mid
print(right)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
l = -1
r = 10 ** 12 + 2
mid = (l + r) // 2
while r - l > 1:
	m = 0
	for i in range(n):
		aa = mid // F[i]
		m += max(0, A[i] - aa)
	if m > k:
		l = mid
	else:
		r = mid
	mid = (l + r) // 2
print(l + 1)


def main():
	(n, k) = map(int, input().split())
	(*a,) = map(int, input().split())
	(*f,) = map(int, input().split())
	a.sort()
	f.sort(reverse=1)
	prod = [(y, x * y) for (x, y) in zip(a, f)]
	l = -1
	r = 10 ** 12
	while r - l > 1:
		m = (l + r) // 2
		s = sum((max(0, 0 - (m - p) // y) for (y, p) in prod))
		if s <= k:
			r = m
		else:
			l = m
	print(r)
main()


import numpy as np
import sys
input = sys.stdin.readline
(N, K) = map(int, input().split())
A = np.sort(list(map(int, input().split())))
F = np.sort(list(map(int, input().split())))[::-1]
mul = A * F
if K >= sum(A) * N:
	print(0)
	return
ma = 2 ** 40
mi = 0
while ma != mi:
	tgt = (ma + mi) // 2
	tmp = np.ceil((mul - tgt) / F)
	num = np.sum(tmp[tmp > 0])
	if num <= K:
		ma = mi + (ma - mi) // 2
	else:
		mi = mi + (ma - mi) // 2 + 1
print(ma)


(n, k) = map(int, input().split())
abilities = sorted(list(map(int, input().split())))
foods = sorted(list(map(int, input().split())), reverse=True)
if sum(abilities) <= k:
	print(0)
	exit()

def check(score):
	ret = 0
	for (a, f) in zip(abilities, foods):
		ret += max(0, (a * f - score + f - 1) // f)
	return ret <= k
ok = 10 ** 12 + 1
ng = 0
for _ in range(50):
	mid = (ok + ng) // 2
	if check(mid):
		ok = mid
	else:
		ng = mid
print(ok)


(n, k) = map(int, input().split())
a = sorted(list(map(int, input().split())))
f = sorted(list(map(int, input().split())), reverse=True)
(ok, ng) = (a[-1] * f[0], -1)
while ok - ng > 1:
	x = (ok + ng) // 2
	tmp = 0
	for i in range(n):
		tmp += max(0, a[i] - x // f[i])
	if tmp > k:
		ng = x
	else:
		ok = x
print(ok)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A = sorted(A)
F = sorted(F, reverse=True)
l = -1
r = 10 ** 12 + 5
while l + 1 < r:
	c = (l + r) // 2
	tmp = 0
	for i in range(N):
		tmp += max(0, A[i] - c // F[i])
	if tmp <= K:
		r = c
	else:
		l = c
print(r)


import sys
import numpy as np
sr = lambda : sys.stdin.readline().rstrip()
ir = lambda : int(sr())
lr = lambda : list(map(int, sr().split()))
(N, K) = lr()
A = np.array(lr())
A.sort()
F = np.array(lr())
F.sort()
F = F[::-1]

def check(x):
	limit = x // F
	Y = A - limit
	if np.any(Y > K):
		return False
	cost = Y[Y >= 0].sum()
	if cost <= K:
		return True
	else:
		return False
ok = 10 ** 15
ng = -1
while abs(ng - ok) > 1:
	mid = (ok + ng) // 2
	if check(mid):
		ok = mid
	else:
		ng = mid
print(ok)


(N, K) = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse=True)
ok = 10 ** 12
ng = 0
while abs(ok - ng) > 0:
	center = (ok + ng) // 2
	cnt = 0
	for i in range(N):
		ap = center // F[i]
		cnt += max(0, A[i] - ap)
		if K < cnt:
			ng = center + 1
			break
	else:
		ok = center
print(ok)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
ng = -1
ok = 10 ** 12 + 100
while ok - ng > 1:
	mid = (ok + ng) // 2
	c = 0
	for (a, f) in zip(A, F):
		c += max(0, a - mid // f)
	if c <= K:
		ok = mid
	else:
		ng = mid
print(ok)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort(reverse=True)
high = 10 ** 18 + 1
low = -1
while high - low > 1:
	res = k
	mid = (low + high) // 2
	for i in range(n):
		res -= max(0, a[i] - mid // b[i])
	if res < 0:
		low = mid
	else:
		high = mid
print(high)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
ok = 10 ** 12
ng = -1
while ok - ng > 1:
	X = (ok + ng) // 2
	tmp = 0
	for i in range(N):
		tmp += max(A[i] - X // F[i], 0)
	if tmp <= K:
		ok = X
	else:
		ng = X
print(ok)


(N, K) = map(int, input().split())
(A, F) = [list(map(int, input().split())) for i in range(2)]
A.sort()
F.sort()
(l, r) = (-1, 10 ** 18)
while r - l > 1:
	h = (l + r) // 2
	k = 0
	for i in range(N):
		k += max(0, A[i] - h // F[-i - 1])
		if k > K:
			k = -1
			break
	if k >= 0:
		r = h
	else:
		l = h
print(r)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort(reverse=True)
f.sort()
z = list(zip(a, f))
ok = max((x * y for (x, y) in z))
ng = -1
while ok - ng > 1:
	mid = (ok + ng) // 2
	if sum((x - mid // y for (x, y) in z if x * y > mid)) <= k:
		ok = mid
	else:
		ng = mid
print(ok)


import sys
readline = sys.stdin.readline
import numpy as np
(N, K) = list(map(int, readline().split()))
A = np.sort(np.array(readline().split(), dtype=int))
F = np.sort(np.array(readline().split(), dtype=int))[::-1]
ng = -1
ok = F[0] * A[-1]

def isOk(x):
	return A.sum() - np.minimum(A, x // F).sum() <= K
while abs(ok - ng) > 1:
	mid = abs(ok + ng) // 2
	if isOk(mid):
		ok = mid
	else:
		ng = mid
print(ok)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
f.sort()
a.sort()
a.reverse()
l = 0
r = 10 ** 12 + 1
import math
while r - l > 1:
	mid = (l + r) / 2
	cnt = 0
	for i in range(n):
		if a[i] * f[i] > mid:
			cnt += a[i] - mid // f[i]
	if cnt <= k:
		r = mid
	else:
		l = mid
print(int(r))


import numpy as np
(N, K) = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse=True)
A = np.array(A, np.int64)
F = np.array(F, np.int64)
Asum = sum(A)

def test(X):
	return Asum - np.minimum(A, X // F).sum() <= K
l = -1
r = 10 ** 12
while l + 1 < r:
	mid = (l + r) // 2
	if test(mid):
		r = mid
	else:
		l = mid
ans = r
print(ans)


import numpy as np
(N, K) = map(int, input().split())
A = np.array(tuple(map(int, input().split())))
F = np.array(tuple(map(int, input().split())))
if sum(A) <= K:
	print(0)
else:

	def solve(N, K, A, F):
		A = np.sort(A)
		F = np.sort(F)[::-1]
		l = -1
		r = 10 ** 12
		while r - l > 1:
			mid = (r + l) // 2
			fmid = np.fmax([0] * N, A - mid // F).sum()
			if fmid <= K:
				r = mid
			else:
				l = mid
		return r
	print(solve(N, K, A, F))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
l = 0
r = max(a) * max(f)

def check(x):
	tot = 0
	for i in range(n):
		need = a[i] - x // f[i]
		tot += need if need >= 0 else 0
	return tot <= k
while l < r:
	m = (l + r) // 2
	if check(m):
		r = m
	else:
		l = m + 1
print(r)


import math
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A = sorted(A, reverse=False)
F = sorted(F, reverse=True)
a = -1
b = max([A[i] * F[-i - 1] for i in range(N)])
while b - a > 1:
	tmp = (a + b) // 2
	c = sum([max(0, math.ceil(A[i] - tmp / F[i])) for i in range(N)])
	if c <= K:
		b = tmp
	else:
		a = tmp
print(b)


import numpy as np
(N, K) = map(int, input().split())
A = np.array(input().split(), np.int64)
F = np.array(input().split(), np.int64)
A.sort()
F.sort()
F = F[::-1]
dig = A.sum()

def judge(x):
	return dig - np.minimum(A, x // F).sum() <= K
l = -1
r = 10 ** 18 + 1
while l + 1 < r:
	test = (l + r) // 2
	if judge(test):
		r = test
	else:
		l = test
print(r)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)

def isOk(T):
	ret = 0
	for (a, f) in zip(A, F):
		ret += max(0, a - T // f)
	return ret <= K
ok = max((a * f for (a, f) in zip(A, F)))
ng = -1
while ok - ng > 1:
	mid = (ok + ng) // 2
	if isOk(mid):
		ok = mid
	else:
		ng = mid
print(ok)


((_, K), *T) = [map(int, t.split()) for t in open(0)]
(A, B) = map(sorted, T)
d = [2 ** 40, 0]
exec('i=sum(d)//2;d[sum(max(0,a-i//b)for a,b in zip(A,B[::-1]))>K]=i;' * 41)
print(d[0])


(N, K) = map(int, input().split())
A = [int(c) for c in input().split()]
F = [int(c) for c in input().split()]
A.sort()
F.sort(reverse=True)
M = 0
for i in range(N):
	if A[i] * F[i] > M:
		M = A[i] * F[i]
l = -1
r = M + 1
while l + 1 < r:
	s = (l + r) // 2
	cnt = 0
	for i in range(N):
		b = s // F[i]
		cnt += max(0, A[i] - b)
	if cnt > K:
		l = s
	else:
		r = s
print(r)


import math
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort(reverse=True)
F.sort()
l = -1
r = A[0] * F[-1]
while l + 1 < r:
	c = (l + r) // 2
	practice = 0
	for i in range(N):
		practice += max(math.ceil(A[i] - c / F[i]), 0)
	if practice <= K:
		r = c
	else:
		l = c
print(r)


def p(F, A, s):
	res = 0
	for i in range(N):
		res += max(A[i] - s // F[i], 0)
	return res
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
F.sort(reverse=True)
A.sort()
l = 0
r = max([F[i] * A[i] for i in range(N)])
while r - l > 1:
	m = (l + r) // 2
	if p(F, A, m) <= K:
		r = m
	else:
		l = m
print(r if p(F, A, 0) > K else 0)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort(reverse=True)
f.sort()
mx = 10 ** 12
mn = -1

def test(buf):
	count = 0
	for i in range(n):
		count += max(0, a[i] - buf // f[i])
		if count > k:
			return False
	return True
while mx - mn > 1:
	buf = (mx + mn) // 2
	if test(buf):
		mx = buf
	else:
		mn = buf
print(mx)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort()
high = max(a) * max(f)
low = 0
while high > low:
	mid = (high + low) // 2
	b = 0
	for i in range(n):
		b += max(a[i] - mid // f[n - i - 1], 0)
	if b > k:
		low = mid + (low == mid)
	else:
		high = mid - (high == mid)
mid = (high + low) // 2
print(mid)


from sys import stdin
import numpy as np

def main():
	readline = stdin.readline
	(n, k) = map(int, readline().split())
	A = np.array(list(map(int, readline().split())), dtype=np.int64)
	A = np.sort(A)[::-1]
	F = np.array(list(map(int, readline().split())), dtype=np.int64)
	F = np.sort(F)
	l = -1
	r = 10 ** 12
	while l < r - 1:
		x = (l + r) // 2
		A_after = np.minimum(x // F, A)
		cnt = (A - A_after).sum()
		if cnt <= k:
			r = x
		else:
			l = x
	print(r)

def __starting_point():
	main()
__starting_point()


import numpy as np
(N, K) = list(map(int, input().split(' ')))
A = list(map(int, input().split(' ')))
F = list(map(int, input().split(' ')))
A.sort()
F.sort(reverse=True)
A = np.array(A)
F = np.array(F)
maxT = np.max(A * F)
left = -1
right = maxT
while left + 1 < right:
	mid = (left + right) // 2
	if np.maximum(0, A - mid // F).sum() <= K:
		right = mid
	else:
		left = mid
print(right)


((_, k), *t) = [map(int, t.split()) for t in open(0)]
(A, F) = map(sorted, t)
o = 10 ** 12
g = -1
while o - g > 1:
	(m, l) = (o + g >> 1, k)
	for (a, f) in zip(A, F[::-1]):
		l -= max(0, a - m // f)
	if l < 0:
		g = m
	else:
		o = m
print(o)


def sub(x):
	global A
	global F
	global K
	s = 0
	for i in range(N):
		s += max(A[i] - x // F[i], 0)
	return s <= K
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
F = list(map(int, input().split()))
F.sort()
F.reverse()
l = -1
r = max(A) * max(F)
while r - l > 1:
	m = (l + r) // 2
	if sub(m):
		r = m
	else:
		l = m
print(r)


def check(mid):
	val = 0
	for i in c:
		if i[0] * i[1] > mid:
			val += i[0] - mid // i[1]
	return val <= k

def bs():
	l = 0
	r = 1e+18
	while l <= r:
		mid = (l + r) // 2
		if check(mid):
			r = mid - 1
		else:
			l = mid + 1
	return r + 1
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort(reverse=True)
c = [[a[i], b[i]] for i in range(n)]
print(int(bs()))


import numpy as np
(N, K) = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.int64)
F = np.array(input().split(), dtype=np.int64)
A = np.sort(A)
F = np.sort(F)[::-1]

def C(x):
	train = np.maximum(0, A - x // F).sum()
	return train <= K
left = -1
right = 10 ** 12 + 1
while right > left + 1:
	mid = (right + left) // 2
	if C(mid):
		right = mid
	else:
		left = mid
ans = right
print(ans)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
la = 10 ** 12 + 1
sm = -1
while sm + 1 < la:
	mi = (sm + la) // 2
	y = 0
	for i in range(N):
		y += max(0, A[i] - mi // F[i])
	if y <= K:
		la = mi
	else:
		sm = mi
print(la)


import sys
input = sys.stdin.readline

def main():
	(N, K) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	F = list(map(int, input().split()))
	A.sort()
	F.sort(reverse=True)
	r = A[-1] * F[0]
	l = -1
	while r - l > 1:
		tmp = (l + r) // 2
		k = 0
		for (x, y) in zip(A, F):
			if x * y > tmp:
				k += x - tmp // y
		if K >= k:
			r = tmp
		else:
			l = tmp
	print(r)
main()


import sys
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
(l, r) = (-1, 10 ** 12 + 1)
while r - l > 1:
	m = (l + r) // 2
	cnt = 0
	for i in range(n):
		cnt += max(0, a[i] - m // f[i])
	if cnt <= k:
		r = m
	else:
		l = m
print(r)


(N, K) = map(int, input().split())
A = sorted([int(a) for a in input().split()])
F = sorted([int(a) for a in input().split()])[::-1]
l = -1
r = 10 ** 18
while r - l > 1:
	m = (l + r) // 2
	if sum([max(0, A[i] - m // F[i]) for i in range(N)]) <= K:
		r = m
	else:
		l = m
print(r)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
m = 0
for i in range(n):
	m += a[i] * f[i]
(l, r) = (-1, m)
while l + 1 != r:
	m = (l + r) // 2
	tmp = 0
	for i in range(n):
		tmp += max(a[i] - m // f[i], 0)
	if k < tmp:
		l = m
	else:
		r = m
print(r)


def main():
	import numpy as np
	(n, k) = list(map(int, input().split()))
	aa = np.array(sorted(list(map(int, input().split()))), dtype=np.int64)
	f = np.array(sorted(list(map(int, input().split())), reverse=True), dtype=np.int64)
	a = 0
	b = 10 ** 12 + 10
	while a + 1 < b:
		med = (a + b) // 2
		if np.sum(np.maximum(aa - med // f, np.zeros(n, dtype=np.int64))) > k:
			a = med + 1
		else:
			b = med
	if a == b:
		print(a)
	elif np.sum(np.maximum(aa - a // f, np.zeros(n, dtype=np.int64))) > k:
		print(b)
	else:
		print(a)
main()


(n, k) = map(int, input().split())
A = [int(i) for i in input().split()]
F = [int(i) for i in input().split()]
A.sort()
F.sort()

def chk(x):
	ct = 0
	for i in range(n):
		(a, f) = (A[i], F[-i - 1])
		ct += max(0, a - x // f)
	if ct <= k:
		return True
	else:
		return False
(l, r) = (0, A[-1] * F[-1])
while r - l > 1:
	m = (l + r) // 2
	if chk(m):
		r = m
	else:
		l = m
if chk(l):
	print(l)
else:
	print(r)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=1)
su = ok = ng = 0
for i in range(n):
	ok = max(ok, a[i] * f[i])
	su += a[i]
if su <= k:
	print(0)
	exit()
while ng + 1 != ok:
	mid = (ok + ng) // 2
	b = [mid // i for i in f]
	b.sort()
	h = 0
	for i in range(n):
		h += max(0, a[i] - b[i])
	if h <= k:
		ok = mid
	else:
		ng = mid
print(ok)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)

def check(s):
	ret = 0
	for (i, j) in zip(a, f):
		ret += max(0, i - s // j)
	return ret <= k
ok = 10 ** 12 + 1
ng = -1
while ok - ng > 1:
	mid = (ok + ng) // 2
	if check(mid):
		ok = mid
	else:
		ng = mid
print(ok)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)

def ok(p):
	result = 0
	for i in range(n):
		result += max(a[i] - p // f[i], 0)
	if result <= k:
		return True
	return False
L = 0
U = a[-1] * f[0]
while U - L >= 1:
	M = (U + L) // 2
	if ok(M):
		U = M
	else:
		L = M + 1
print(U)


import numpy as np
(n, k) = map(int, input().split())
a = np.array(input().split(), dtype=np.int64)
f = np.array(input().split(), dtype=np.int64)
a.sort()
f.sort()
f = f[::-1]
af = a * f

def safe(r):
	return np.maximum(0, (af - r + f - 1) // f).sum() <= k
m = -1
M = 10 ** 12
while m + 1 < M:
	pos = (m + M) // 2
	if safe(pos):
		M = pos
	else:
		m = pos
print(M)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
left = -1
right = 10 ** 12 + 1
while right - left > 1:
	mid = (left + right) // 2
	cnt = 0
	for i in range(N):
		tmp = max(A[i] - mid // F[i], 0)
		cnt += tmp
	if cnt <= K:
		right = mid
	else:
		left = mid
print(right)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
r = max(a) * max(f)
l = -1
while r - l > 1:
	c = (r + l) // 2
	ans = 0
	for j in range(n):
		ans += max(a[j] - c // f[j], 0)
	if ans <= k:
		r = c
	else:
		l = c
print(r)


(n, k) = list(map(int, input().split()))
a = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]
a.sort()
f.sort(reverse=True)

def score(x):
	syugyo = 0
	for (A, F) in zip(a, f):
		sup = x // F
		if sup < A:
			syugyo += A - sup
	if syugyo <= k:
		return True
	return False
left = 0
right = a[-1] * f[0] + 1
while left < right - 1:
	mid = (left + right) // 2
	if score(mid):
		right = mid
	else:
		left = mid
print(left + 1 if left != 0 else 0)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
k = max(sum(a) - k, 0)
a.sort()
f.sort()
f.reverse()
l = -1
r = a[-1] * f[0] * 2
while l + 1 != r:
	x = (l + r) // 2
	b = []
	for i in range(n):
		b.append(min(x // f[i], a[i]))
	if k <= sum(b):
		r = x
	else:
		l = x
print(r)


import numpy as np

def solve():
	(N, K) = map(int, input().split())
	a_l = np.array(input().split(), int)
	b_l = np.array(input().split(), int)
	a_l.sort()
	b_l.sort()
	b_l = b_l[::-1]
	sum_a = a_l.sum()
	(left, right) = (-1, 10 ** 13)
	while left + 1 < right:
		mid = (left + right) // 2
		if sum_a - np.minimum(a_l, mid // b_l).sum() <= K:
			right = mid
		else:
			left = mid
	print(right)

def __starting_point():
	solve()
__starting_point()


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort(reverse=True)
F.sort()
import math

def isok(n):
	sum = 0
	for i in range(N):
		sum += max(0, A[i] - n // F[i])
	return sum <= K
ma = 0
for i in range(N):
	ma = max(ma, A[i] * F[i])
(start, end) = (-1, ma)
while end - start > 1:
	mid = (start + end) // 2
	if isok(mid):
		end = mid
	else:
		start = mid
print(end)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort()
suma = sum(A)
u = 10 ** 12
d = 0
for i in range(50):
	x = (u + d) // 2
	s = 0
	for i in range(N):
		f = F[i]
		j = -(i + 1)
		a = A[j]
		b = x // f
		s += max(0, a - b)
	if s <= K:
		u = x
	else:
		d = x
print(u)


import math
import numpy as np

def yn(a, f, k, x):
	k_yt = np.maximum(np.zeros(a.shape), a - np.floor(np.divide(x, f)))
	k_yt = np.sum(k_yt)
	if k_yt <= k:
		return True
	else:
		return False
(n, k) = list(map(int, input().split()))
a = list(list(map(int, input().split())))
f = list(list(map(int, input().split())))
a.sort()
f.sort(reverse=True)
xo = max([a[i] * f[i] for i in range(n)])
a = np.array(a)
f = np.array(f)
if xo == 0:
	print(0)
else:
	l = 0
	r = xo
	m = xo
	while l <= r:
		piv = int((r + l) / 2)
		if yn(a, f, k, piv):
			r = piv - 1
			m = piv
		else:
			l = piv + 1
	print(m)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
hi = 10 ** 18
lo = -1
while hi - lo > 1:
	mid = (hi + lo) // 2
	tr = 0
	for i in range(N):
		if A[i] * F[i] > mid:
			tr += A[i] - mid // F[i]
	if tr > K:
		lo = mid
	else:
		hi = mid
print(hi)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)

def isok(m):
	c = 0
	for (i, j) in zip(a, f):
		if i * j >= m:
			c += i - m // j
		if c > k:
			return False
	return True
ok = 10 ** 12 + 1
ng = -1
while abs(ok - ng) > 1:
	m = (ok + ng) // 2
	if isok(m):
		ok = m
	else:
		ng = m
print(ok)


import numpy as np
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
if k > sum(a):
	print(0)
	return
a.sort(reverse=True)
f.sort()
a = np.array(a)
f = np.array(f)
lb = -1
ub = a[0] * f[-1]
while ub - lb > 1:
	x = (lb + ub) // 2
	cx = np.full(n, x)
	ck = a - x // f
	ck = np.where(ck < 0, 0, ck)
	ck_sum = ck.sum()
	if ck_sum > k:
		lb = x
	else:
		ub = x
print(ub)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
AF = [A[i] * F[i] for i in range(N)]
l = -1
r = max(AF)
while l + 1 < r:
	x = (l + r) // 2
	s = sum([max(A[i] - x // F[i], 0) for i in range(N)])
	if s <= K:
		r = x
	else:
		l = x
print(r)


import numpy as np
(N, K) = map(int, input().split())
As = np.sort(list(map(int, input().split())))
Fs = np.sort(list(map(int, input().split())))[::-1]
l = As * Fs
left = 0
right = max(l)
while right - left >= 1:
	mid = left + (right - left) / 2
	if np.maximum(As - mid // Fs, 0).sum() <= K:
		right = mid
	else:
		left = mid
print(int(right))


(N, K) = map(int, input().split())
A = [int(i) for i in input().split()]
F = [int(i) for i in input().split()]
A.sort(reverse=True)
F.sort()
ng = -1
ok = 10 ** 12
while ok - ng > 1:
	mid = (ok + ng) // 2
	k = 0
	for i in range(N):
		k += max(0, A[i] - mid // F[i])
	if k <= K:
		ok = mid
	else:
		ng = mid
print(ok)


(n, k) = map(int, input().split())
alist = list(map(int, input().split()))
flist = list(map(int, input().split()))
alist.sort()
flist.sort(reverse=True)
L = -1
R = 10 ** 18
while R - 1 > L:
	mid = (R + L) // 2
	count = 0
	loop_count = 0
	for i in flist:
		if alist[loop_count] > mid // i:
			count += alist[loop_count] - mid // i
		loop_count += 1
	if count > k:
		L = mid
	else:
		R = mid
print(R)


(n, k) = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse=True)
low = -1
high = 10 ** 12
while high - low > 1:
	score = (low + high) // 2
	training = 0
	for i in range(n):
		if A[i] * F[i] > score:
			training += A[i] - score // F[i]
	if training <= k:
		high = score
	else:
		low = score
print(high)


import sys
import numpy as np
(n, k) = map(int, input().split())
a = np.array(sorted(list(map(int, input().split()))))
f = np.array(sorted(list(map(int, input().split())), reverse=True))
asum = a.sum()
(l, r) = (0, 10 ** 13)
while l != r:
	mid = (l + r) // 2
	can = asum - np.minimum(mid // f, a).sum() <= k
	if can:
		r = mid
	else:
		l = mid + 1
print(l)


import numpy as np

def is_good(mid, key):
	x = A - mid // F
	return x[x > 0].sum() <= key

def binary_search(key):
	(bad, good) = (-1, 10 ** 18)
	while good - bad > 1:
		mid = (bad + good) // 2
		if is_good(mid, key):
			good = mid
		else:
			bad = mid
	return good
(N, K) = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.int64)
F = np.array(input().split(), dtype=np.int64)
A.sort()
F[::-1].sort()
print(binary_search(K))


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
(l, r) = (0, 10 ** 12 + 1)
while l < r:
	mid = (l + r) // 2
	cnt = 0
	for (a, f) in zip(A, F):
		cnt += max(0, a - mid // f)
	if cnt <= k:
		r = mid
	else:
		l = mid + 1
print(l)


import sys
import numpy as np
sr = lambda : sys.stdin.readline().rstrip()
ir = lambda : int(sr())
lr = lambda : list(map(int, sr().split()))
(N, K) = lr()
A = np.array(lr())
F = np.array(lr())
A.sort()
F = np.sort(F)[::-1]

def check(x):
	count = np.maximum(0, A - x // F).sum()
	return count <= K
left = 10 ** 12
right = -1
while left > right + 1:
	mid = (left + right) // 2
	if check(mid):
		left = mid
	else:
		right = mid
print(left)


import numpy as np
from numba import njit
(n, k) = list(map(int, input().split()))
A = np.array(list(map(int, input().split())))
F = np.array(list(map(int, input().split())))
A = np.sort(A)
F = np.sort(F)[::-1]

@njit
def is_ok(x):
	tmp = 0
	for (a, f) in zip(A, F):
		y = a * f
		if y > x:
			tmp += a - x // f
	return tmp <= k
ok = 10 ** 16
ng = -1
while ok - ng > 1:
	mid = (ok + ng) // 2
	if is_ok(mid):
		ok = mid
	else:
		ng = mid
print(ok)


(n, k) = map(int, input().split())
al = list(map(int, input().split()))
fl = list(map(int, input().split()))
al.sort()
fl.sort(reverse=True)
(ok, ng) = (10 ** 12 + 1, -1)
while abs(ok - ng) > 1:
	mid = (ok + ng) // 2
	ok_flag = True
	cnt = 0
	for (a, f) in zip(al, fl):
		v = a * f
		rem = a * f - mid
		cnt += max((rem - 1) // f + 1, 0)
	if cnt <= k:
		ok = mid
	else:
		ng = mid
print(ok)


(n, k) = map(int, input().split())
a = sorted(list(map(int, input().split())))
f = sorted(list(map(int, input().split())), reverse=True)
(l, r) = (0, 10 ** 12)

def cal(x):
	global n, f, a, k
	ret = 0
	for i in range(n):
		ret += max(0, a[i] - x // f[i])
	return ret
while l + 1 < r:
	x = l + (r - l) // 2
	if cal(x) <= k:
		r = x
	else:
		l = x
if cal(l) <= k:
	print(l)
else:
	print(r)


import math
((n, k), a, f) = [list(map(int, s.split())) for s in open(0)]
a.sort()
f.sort(reverse=True)
low = 0
high = 0
for (x, y) in zip(a, f):
	high = max(high, x * y)
while high != low:
	test = int((high + low) // 2)
	tmp = 0
	for (x, y) in zip(a, f):
		tmp += max(0, x - math.floor(test / y))
		if tmp > k:
			low = test + 1
			break
	else:
		high = test
print(high)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)

def calc(x):
	tmp = 0
	for (a, f) in zip(A, F):
		tmp += max(0, a - x // f)
	return tmp
ng = -1
ok = 10 ** 18
while ok - ng > 1:
	mid = (ok + ng) // 2
	if calc(mid) <= K:
		ok = mid
	else:
		ng = mid
print(ok)


(N, K) = input().split()
(N, K) = [int(N), int(K)]
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A = sorted(A)
F = sorted(F, reverse=True)
goal_max = 10 ** 12 + 1
goal_min = 0 - 1
while goal_max - goal_min != 1:
	goal = (goal_max + goal_min) // 2
	counter = 0
	for i in range(N):
		counter += max(0, A[i] - goal // F[i])
	if counter <= K:
		goal_max = goal
	else:
		goal_min = goal
print(goal_max)


(n, k, *a) = map(int, open(0).read().split())
(a, f) = (sorted(a[:n]), sorted(a[n:], reverse=1))
ok = 10 ** 12
ng = -1
while ok - ng > 1:
	mid = (ok + ng) // 2
	l = k
	for (b, g) in zip(a, f):
		t = b - mid // g
		if t > 0:
			l -= t
	if l < 0:
		ng = mid
	else:
		ok = mid
print(ok)


def f(point):
	cnt = 0
	for i in range(N):
		(a, f) = (A[i], F[i])
		cnt += max(0, a - point // f)
	return cnt <= K
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
l = -1
r = 10 ** 12
while r - l > 1:
	mid = (r + l) // 2
	if f(mid):
		r = mid
	else:
		l = mid
print(r)


import numpy as np

def main():
	(N, K) = [int(x) for x in input().split()]
	A = [float(x) for x in input().split()]
	F = [float(x) for x in input().split()]
	A = np.array(sorted(A))
	F = np.array(sorted(F, reverse=True))
	if K >= np.sum(A) * N:
		print(0)
		return
	min_time = 0
	max_time = A[-1] * F[0]
	while max_time != min_time:
		tgt_time = (min_time + max_time) // 2
		ideal_a = np.floor(tgt_time * np.ones(N) / F)
		cost = A - ideal_a
		require_k = np.sum(cost[cost > 0])
		if require_k <= K:
			max_time = tgt_time
		else:
			min_time = tgt_time + 1
	print(int(max_time))

def __starting_point():
	main()
__starting_point()


import numpy as np

def is_good(mid, key):
	return A_sum - np.minimum(A, mid // F).sum() <= key

def binary_search(bad, good, key):
	while good - bad > 1:
		mid = (bad + good) // 2
		if is_good(mid, key):
			good = mid
		else:
			bad = mid
	return good
(N, K) = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.int64)
F = np.array(input().split(), dtype=np.int64)
A.sort()
F[::-1].sort()
A_sum = A.sum()
ans = binary_search(-1, np.max(A * F), K)
print(ans)


import numpy as np

def is_ok(mid, k):
	s = a - mid // f
	s = s[s > 0].sum()
	if s <= k:
		return True
	else:
		return False
(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]
a.sort()
f.sort(reverse=True)
a = np.array(a)
f = np.array(f)
(l, r) = (-1, 10 ** 12)
while l + 1 < r:
	mid = (l + r) // 2
	if is_ok(mid, k):
		r = mid
	else:
		l = mid
print(r)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
(l, r) = (0, 10 ** 18)
if sum(A) <= k:
	print(0)
else:
	while r - l != 1:
		mid = (r + l) // 2
		ex = 0
		for i in range(n):
			need = mid // F[i]
			ex += max(0, A[i] - need)
		if ex <= k:
			r = mid
		else:
			l = mid
	print(r)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
lef = -1
rig = 10 ** 13
while rig - lef != 1:
	now = (rig + lef) // 2
	cou = 0
	for i in range(n):
		t = now // f[i]
		cou += max(0, a[i] - t)
	if cou <= k:
		rig = now
	elif cou > k:
		lef = now
print(rig)


import sys
import numpy as np
(N, K) = map(int, input().split())
A = np.array([int(i) for i in input().split()])
F = np.array([int(i) for i in input().split()])
A = np.sort(A)
F = np.sort(F)[::-1]
Asum = A.sum()

def test(x):
	return Asum - np.minimum(A, x // F).sum() <= K
l = 0
r = 10 ** 18 * 2 + 1
while r - l > 1:
	m = (l + r) // 2
	if test(m):
		r = m
	else:
		l = m
if test(l):
	print(l)
else:
	print(l + 1)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
if sum(A) <= K:
	print(0)
	exit()

def ok(c):
	s = 0
	for i in range(N):
		s += max(0, A[i] - c // F[i])
	return s <= K
A.sort()
F.sort(reverse=True)
(l, r) = (-1, 10 ** 12)
while l + 1 < r:
	c = (l + r) // 2
	if ok(c):
		r = c
	else:
		l = c
print(r)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
l = -1
r = 10 ** 12 + 10
while l + 1 < r:
	mid = (l + r) // 2
	s = 0
	for i in range(N):
		s += max(0, A[i] - mid // F[i])
	if s <= K:
		r = mid
	else:
		l = mid
print(r)


(n, k) = map(int, input().split())
a = sorted(map(int, input().split()))
f = sorted(map(int, input().split()), reverse=True)
(lo, hi) = (-1, 10 ** 18 + 1)
while hi - lo > 1:
	mid = (lo + hi) // 2
	if sum((max(0, a[i] - mid // f[i]) for i in range(n))) <= k:
		hi = mid
	else:
		lo = mid
print(hi)


import numpy as np

def solve(*args: str) -> str:
	(n, k) = list(map(int, args[0].split()))
	A = np.array(sorted(list(map(int, args[1].split()))))
	F = np.array(sorted(list(map(int, args[2].split())), reverse=True))
	right = 1 + A[-1] * F[0]
	left = -1
	total = A.sum()
	while left + 1 < right:
		mid = (left + right) // 2
		if total - np.minimum(A, mid // F).sum() <= k:
			right = mid
		else:
			left = mid
	return str(right)

def __starting_point():
	print(solve(*open(0).read().split('\n')))
__starting_point()


(n, k) = map(int, input().split())
a = map(int, input().split())
f = map(int, input().split())
a = sorted(a)
f = sorted(f)[::-1]

def c(x):
	res = 0
	for (O, K) in zip(a, f):
		d = max(0, O * K - x)
		res += (d + K - 1) // K
	return res <= k
l = -1
r = 1 << 60
while r - l > 1:
	mid = l + r >> 1
	if c(mid):
		r = mid
	else:
		l = mid
print(r)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a = sorted(a)[::-1]
f = sorted(f)
ok = 10 ** 18
ng = -1
import math

def isOK(val, arr, farr, k):
	s = 0
	for i in range(len(arr)):
		s += max(math.ceil(a[i] - val / f[i]), 0)
	return s <= k
while abs(ok - ng) > 1:
	mid = abs(ok + ng) // 2
	if isOK(mid, a, f, k):
		ok = mid
	else:
		ng = mid
print(ok)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
ng = -1
ok = 10 ** 18
while ok - ng > 1:
	mid = (ok + ng) // 2
	c = 0
	for i in range(N):
		c += max(0, A[i] - mid // F[i])
	if c <= K:
		ok = mid
	else:
		ng = mid
print(ok)


(n, k, *a) = map(int, open(0).read().split())
z = (sorted(a[:n]), sorted(a[n:])[::-1])
o = 10 ** 12
g = -1
while o - g > 1:
	(m, l) = (o + g >> 1, k)
	for (a, f) in zip(*z):
		l -= max(0, a - m // f)
	if l < 0:
		g = m
	else:
		o = m
print(o)


import numpy as np

def solve(n, k, a, f):
	a = sorted(a)
	f = sorted(f)[::-1]
	a = np.asarray(a, dtype=int)
	f = np.asarray(f, dtype=int)
	total = np.sum(a)
	l = -1
	r = np.max(a * f)
	while r - l > 1:
		th = (l + r) // 2
		cost = total - np.minimum(a, th // f).sum()
		if cost <= k:
			r = th
		else:
			l = th
	return r
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
print(solve(n, k, a, f))


import numpy as np
(N, K) = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.int64)
F = np.array(input().split(), dtype=np.int64)
A = np.sort(A)
F = np.sort(F)
F = F[::-1]

def C(m):
	need = m // F
	cost = A - need
	cost[cost < 0] = 0
	return cost.sum() <= K
(l, r) = (-1, 10 ** 18 + 10)
while r - l > 1:
	m = (r + l) // 2
	if C(m):
		r = m
	else:
		l = m
print(r)


(i, s) = (lambda : map(int, input().split()), sorted)
(n, k) = i()
z = (s(i()), s(i())[::-1])
o = 10 ** 12
g = -1
while o - g > 1:
	(m, l) = (o + g >> 1, k)
	for (a, f) in zip(*z):
		l -= max(0, a - m // f)
	if l < 0:
		g = m
	else:
		o = m
print(o)


import math
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a = sorted(a)
f = sorted(f, reverse=True)
l = -1
r = 2 * 10 ** 12 + 1
while l + 1 < r:
	c = (l + r) // 2
	s = 0
	for i in range(n):
		m = max(0, math.ceil((a[i] * f[i] - c) / f[i]))
		s = s + m
	if s > k:
		l = c
	else:
		r = c
print(r)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)

def is_ok(m):
	c = 0
	for (a, f) in zip(A, F):
		d = m // f
		c += max(0, a - d)
		if c > K:
			return False
	return True
ok = 10 ** 13
ng = -1
while ok - ng > 1:
	m = (ok + ng) // 2
	if is_ok(m):
		ok = m
	else:
		ng = m
print(ok)


import math
(N, K, *AF) = map(int, open(0).read().split())
A = sorted(AF[:N])
F = sorted(AF[N:], reverse=True)
left = 0
right = max(A) * max(F)
while left != right:
	mid = (left + right) // 2
	temp = 0
	for i in range(N):
		temp += max(A[i] - math.floor(mid / F[i]), 0)
		if temp > K:
			left = mid + 1
			break
	else:
		right = mid
print(left)


import sys
input = sys.stdin.readline
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
import numpy as np
A = np.array(A)
F = np.array(F)
A = np.sort(A)[::-1]
F = np.sort(F)
B = np.sum(A)
M = max([a * f for (a, f) in zip(A, F)])

def is_possible(x):
	return B - np.minimum(A, x // F).sum() <= K
left = -1
right = M
while left + 1 < right:
	mid = (left + right) // 2
	if is_possible(mid):
		right = mid
	else:
		left = mid
print(right)


(N, K) = map(int, input().split())
costs = list(map(int, input().split()))
foods = list(map(int, input().split()))
foods.sort()
costs.sort(reverse=True)

def can_eat(x):
	count = 0
	for i in range(N):
		count += max(0, costs[i] - x // foods[i])
	return count <= K
(l, r) = (-1, 10 ** 12 + 1)
while r - l > 1:
	mid = (l + r) // 2
	if can_eat(mid):
		r = mid
	else:
		l = mid
print(r)


def main():
	(N, K, *I) = map(int, open(0).read().split())
	(A, F) = (I[:N], I[N:])
	A.sort()
	F.sort(reverse=True)
	(ng, ok) = (-1, 10 ** 12)
	while abs(ok - ng) > 1:
		mid = (ok + ng) // 2
		if sum((max(0, a - mid // f) for (a, f) in zip(A, F))) <= K:
			ok = mid
		else:
			ng = mid
	print(ok)
main()


import heapq
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
f = list(map(int, input().split()))
f.sort(reverse=True)
asum = sum(a)

def test(x):
	t = [min(a[i], x // f[i]) for i in range(n)]
	return asum - sum(t)
ng = -1
ok = 10 ** 13
while abs(ok - ng) > 1:
	mid = (ok + ng) // 2
	if test(mid) <= k:
		ok = mid
	else:
		ng = mid
print(ok)


(N, K) = map(int, input().split())
As = list(map(int, input().split()))
Fs = list(map(int, input().split()))
As.sort()
Fs.sort(reverse=True)

def check(x):
	k = 0
	for i in range(N):
		k += max(0, As[i] - x // Fs[i])
	return k <= K
a = 0
b = As[-1] * Fs[0]
while a < b:
	i = (a + b) // 2
	if check(i):
		b = i
	else:
		if a == i:
			break
		a = i
r = b
print(r)


(n, k) = map(int, input().split())
aa = list(map(int, input().split()))
ff = list(map(int, input().split()))
a = sorted(aa, reverse=True)
f = sorted(ff)

def C(x):
	ret = 0
	for i in range(n):
		ret += max(0, a[i] - x // f[i])
	return ret
lb = -1
ub = 10 ** 12 + 1
while ub - lb > 1:
	mid = (ub + lb) // 2
	if C(mid) > k:
		lb = mid
	else:
		ub = mid
print(ub)


import sys
input = sys.stdin.readline
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
MIN = 0
MAX = max(A) * max(F)
while MIN != MAX:
	mid = (MIN + MAX) // 2
	score = 0
	for i in range(N):
		if A[i] * F[i] > mid:
			score += A[i] - mid // F[i]
	if score <= K:
		MAX = mid
	else:
		MIN = mid + 1
print(MIN)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
hi = 10 ** 12
lo = 0

def c(mi):
	tmp = 0
	for (i, j) in zip(a, f):
		if mi // j < i:
			tmp += i - mi // j
	if tmp <= k:
		return True
	return False
while hi >= lo:
	mi = (hi + lo) // 2
	if c(mi):
		hi = mi - 1
	else:
		lo = mi + 1
print(lo)


(n, k) = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse=True)
ng = -1
ok = 10 ** 12 + 10
while ok - ng > 1:
	mid = (ok + ng) // 2
	a = 0
	for i in range(n):
		a = a + max(0, A[i] - mid // F[i])
	if a > k:
		ng = mid
	else:
		ok = mid
print(ok)


(n, k) = map(int, input().split())
a_ls = list(map(int, input().split()))
f_ls = list(map(int, input().split()))
a_ls.sort(reverse=True)
f_ls.sort()
l = -1
r = a_ls[0] * f_ls[-1]
while l + 1 < r:
	c = (l + r) // 2
	total = 0
	for i in range(n):
		a = max(a_ls[i] * f_ls[i] - c, 0)
		b = f_ls[i]
		total += (a + b - 1) // b
	if total > k:
		l = c
	else:
		r = c
print(r)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import time, random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def bs(f, mi, ma):
	mm = -1
	while ma > mi:
		mm = (ma + mi) // 2
		if f(mm):
			mi = mm + 1
		else:
			ma = mm
	if f(mm):
		return mm + 1
	return mm

def main():
	(n, k) = LI()
	a = sorted(LI())
	b = sorted(LI(), reverse=True)
	if sum(a) <= k:
		return 0

	def f(i):
		t = 0
		for (ai, bi) in zip(a, b):
			u = i // bi
			if ai > u:
				t += ai - u
		return t > k
	r = bs(f, 0, 10 ** 12)
	return r
print(main())


import numpy as np
(N, K) = map(int, input().split())
A = np.array(list(map(int, input().split())))
F = np.array(list(map(int, input().split())))
A.sort()
F.sort()
A = A[::-1]
left = 0
right = np.max(A * F)
for _ in range(50):
	judge = (left + right) // 2
	rec = judge // F
	recK = np.sum(np.maximum(np.zeros(N), A - rec))
	if recK <= K:
		right = judge
	else:
		left = judge + 1
	if left == right:
		print(left)
		break


import sys
import numpy as np
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20

def I():
	return int(input())

def F():
	return float(input())

def S():
	return input()

def LI():
	return [int(x) for x in input().split()]

def LI_():
	return [int(x) - 1 for x in input().split()]

def LF():
	return [float(x) for x in input().split()]

def LS():
	return input().split()

def resolve():
	(N, K) = LI()
	A = np.array(LI())
	F = np.array(LI())
	A.sort()
	F.sort()
	F = F[::-1]

	def can_complete(t):
		return np.maximum(0, A - t // F).sum() <= K
	ng = -1
	ok = max(A) * max(F)
	while abs(ok - ng) > 1:
		m = (ng + ok) // 2
		if can_complete(m):
			ok = m
		else:
			ng = m
	print(ok)

def __starting_point():
	resolve()
__starting_point()


import sys
import numpy as np
input = sys.stdin.readline

def main():
	(N, K) = map(int, input().split())
	a = np.array(sorted(list(map(int, input().split()))))
	f = np.array(sorted(list(map(int, input().split())), reverse=True))
	Asum = a.sum()
	(l, r) = (0, int(10000000000000.0))
	while l != r:
		p = (l + r) // 2
		tmp = Asum - np.minimum(a, p // f).sum() <= K
		if tmp:
			r = p
		else:
			l = p + 1
	print(l)

def __starting_point():
	main()
__starting_point()


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort()
import numpy as np
a = np.array(a)
f = np.array(f)
f_ = f[::-1]
left = -1
right = np.max(a * f_)
while left + 1 < right:
	mid = (left + right) // 2
	x = np.maximum(0, a - mid // f_).sum() <= k
	if x:
		right = mid
	else:
		left = mid
print(right)


(N, K) = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse=True)
(minT, maxT) = (-1, max([A[i] * F[i] for i in range(N)]))
while maxT - minT > 1:
	midT = minT + (maxT - minT) // 2
	if sum([max(A[i] - midT // F[i], 0) for i in range(N)]) > K:
		minT = midT
	else:
		maxT = midT
print(maxT)


(N, K) = map(int, input().split())
A = sorted([int(a) for a in input().split()])
F = sorted([int(f) for f in input().split()], reverse=True)
INF = 10 ** 12 + 10
l = -1
r = INF
while r - l > 1:
	c = (l + r) // 2
	SUM_B = 0
	for i in range(N):
		SUM_B += max(0, A[i] - c // F[i])
	if SUM_B <= K:
		r = c
	else:
		l = c
print(r)


(n, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort(reverse=True)
F.sort()
ng = -1
ok = 10 ** 18 + 1
while ok - ng > 1:
	mid = (ng + ok) // 2
	k = K
	for (a, f) in zip(A, F):
		k -= max(0, a - mid // f)
	if k < 0:
		ng = mid
	else:
		ok = mid
print(ok)


import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
(N, K) = list(map(int, input().split()))
A = np.array(list(map(int, input().split())), dtype=np.int64)
F = np.array(list(map(int, input().split())), dtype=np.int64)
A.sort()
F.sort()
F = F[::-1]
l = 0
r = 10 ** 12 + 100

def solve(num):
	B = num // F
	tmp = np.sum(np.maximum(0, A - B))
	if tmp <= K:
		return 1
	else:
		return 0
while r - l > 1:
	mid = (l + r) // 2
	if solve(mid):
		r = mid
	else:
		l = mid
if solve(l):
	print(l)
else:
	print(r)


import math
(N, K) = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)
F = sorted([int(i) for i in input().split()])
OK = 10 ** 12
NG = -1
while OK - NG > 1:
	mid = (OK + NG) // 2
	cnt = 0
	for (a, f) in zip(A, F):
		if a * f > mid:
			cnt += math.ceil((a * f - mid) / f)
	if cnt <= K:
		OK = mid
	else:
		NG = mid
print(OK)


(N, K) = map(int, input().split())
A = sorted(map(int, input().split()))
F = sorted(map(int, input().split()))[::-1]
(left, right) = (-1, 10 ** 12)
while left + 1 < right:
	mid = (left + right) // 2
	if sum([max(0, a - mid // f) for (a, f) in zip(A, F)]) > K:
		left = mid
	else:
		right = mid
print(right)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)

def check(mid):
	cnt = 0
	for i in range(N):
		tmp = mid // F[i]
		cnt += max(A[i] - tmp, 0)
	return cnt <= K
check(2)
(l, r) = (-1, 10 ** 30)
while r - l > 1:
	mid = (l + r) // 2
	if check(mid):
		r = mid
	else:
		l = mid
print(r)