This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only.

Waking up in the morning, Apollinaria decided to bake cookies. To bake one cookie, she needs n ingredients, and for each ingredient she knows the value a_{i} — how many grams of this ingredient one needs to bake a cookie. To prepare one cookie Apollinaria needs to use all n ingredients.

Apollinaria has b_{i} gram of the i-th ingredient. Also she has k grams of a magic powder. Each gram of magic powder can be turned to exactly 1 gram of any of the n ingredients and can be used for baking cookies.

Your task is to determine the maximum number of cookies, which Apollinaria is able to bake using the ingredients that she has and the magic powder.


-----Input-----

The first line of the input contains two positive integers n and k (1 ≤ n, k ≤ 1000) — the number of ingredients and the number of grams of the magic powder.

The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 1000), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie.

The third line contains the sequence b_1, b_2, ..., b_{n} (1 ≤ b_{i} ≤ 1000), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has.


-----Output-----

Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.


-----Examples-----
Input
3 1
2 1 4
11 3 16

Output
4

Input
4 3
4 3 5 6
11 12 14 20

Output
3



-----Note-----

In the first sample it is profitably for Apollinaria to make the existing 1 gram of her magic powder to ingredient with the index 2, then Apollinaria will be able to bake 4 cookies.

In the second sample Apollinaria should turn 1 gram of magic powder to ingredient with the index 1 and 1 gram of magic powder to ingredient with the index 3. Then Apollinaria will be able to bake 3 cookies. The remaining 1 gram of the magic powder can be left, because it can't be used to increase the answer.

Difficulty: MEDIUM
Tags: Sorting

Implementation

Complete search
Skill types: Sorting

Complete search

Starter code:

Solutions:
(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
cook = 0
f = True
while f:
	for i in range(n):
		if b[i] >= a[i]:
			b[i] -= a[i]
		elif k >= a[i] - b[i]:
			k -= a[i] - b[i]
			b[i] = 0
		else:
			f = False
	if f:
		cook += 1
print(cook)


import math
(n, k) = map(int, input().split())
cost = list(map(int, input().split()))
stock = list(map(int, input().split()))
lo = 0
hi = 2000000000
mid = 0
while lo < hi:
	oldmid = mid
	mid = math.ceil((lo + hi) // 2)
	need = 0
	for i in range(n):
		need += max(0, cost[i] * mid - stock[i])
	if need == k or oldmid == mid:
		break
	elif need < k:
		lo = mid
	else:
		hi = mid
print(mid)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def solve(ind):
	pp = 0
	x = l3[ind][0]
	for i in range(0, ind):
		(tam, kal, ger) = l3[i]
		if tam < x:
			t = ger - kal + (x - tam - 1) * ger
		else:
			t = 0
		pp += t
	if pp <= k:
		return True
	else:
		return False

def binary(data, low, high):
	if low > high:
		return high
	else:
		mid = int((low + high) / 2)
		st = solve(mid)
		if st == True:
			return binary(data, mid + 1, high)
		else:
			return binary(data, low, mid - 1)
(n, k) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = []
for i in range(n):
	(tam, kal) = divmod(l2[i], l1[i])
	l3.append([tam, kal, l1[i]])
l3.sort()
res = binary(l3, 0, n - 1)
x = l3[res][0]
pp = 0
ss = 0
hh = 0
for i in range(res + 1):
	(tam, kal, ger) = l3[i]
	ss += ger
	if tam < x:
		t = ger - kal + (x - tam - 1) * ger
	else:
		t = 0
		hh += l3[i][1]
	pp += t
kal = k - pp
p1 = ss - hh
if kal - p1 > 0:
	kal -= p1
	print(x + 1 + kal // ss)
elif kal - p1 == 0:
	print(x + 1)
elif kal - p1 < 0:
	print(x)


def bake(n, k, ai, bi):
	min_cookies = bi[0] // ai[0]
	for j in range(1, n):
		cookies = bi[j] // ai[j]
		if cookies < min_cookies:
			min_cookies = cookies
	possible = True
	while possible:
		cks = min_cookies + 1
		tenk = k
		for j in range(n):
			if bi[j] < cks * ai[j]:
				tenk = tenk - (cks * ai[j] - bi[j])
				if tenk < 0:
					possible = False
					return min_cookies
		min_cookies = cks
	return min_cookies

def main():
	(n, k) = [int(i) for i in input().strip().split()]
	ai = [int(i) for i in input().strip().split()]
	bi = [int(i) for i in input().strip().split()]
	ans = bake(n, k, ai, bi)
	print(ans)

def __starting_point():
	main()
__starting_point()


(n, k) = input().split()
n = int(n)
k = int(k)
a = []
a = input().split()
b = input().split()
for i in range(n):
	(a[i], b[i]) = (int(a[i]), int(b[i]))
min = b[0] // a[0]
for i in range(1, n):
	if min > b[i] // a[i]:
		min = b[i] // a[i]
qty1 = min
baln = [0 for i in range(n)]
f = 1
qty2 = 0
for i in range(n):
	b[i] -= a[i] * min
diff = 0
for i in range(n):
	if a[i] - b[i] > 0:
		diff += a[i] - b[i]
	else:
		baln[i] += b[i] - a[i]
if diff > k:
	k = 0
	qty2 = 0
elif diff == k:
	k = 0
	qty2 += 1
else:
	qty2 += 1
	k -= diff
	while sum(baln) != 0 or f == 1:
		f = 0
		diff = 0
		for i in range(n):
			if a[i] - baln[i] > 0:
				diff += a[i] - baln[i]
				baln[i] = 0
			else:
				baln[i] = baln[i] - a[i]
		if diff > k:
			k = 0
			qty2 += 0
			break
		elif diff == k:
			k = 0
			qty2 += 1
			break
		else:
			k -= diff
			qty2 += 1
print(qty1 + qty2 + k // sum(a))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
left = 0
right = 10 ** 9
while left != right:
	p = 0
	if right - left == 1:
		p = 1
	fnd = (left + right) // 2
	sm = 0
	for i in range(n):
		sm += max(0, fnd * a[i] - b[i])
	if sm > k:
		right = fnd
	else:
		left = fnd + p
print(left - 1)


(n, k) = input().split()
n = int(n)
k = int(k)
a = list(map(int, input().split()))
b = list(map(int, input().split()))
L = 0
R = 10 ** 10

def check(idd):
	summ = 0
	for i in range(0, n):
		if a[i] * idd > b[i]:
			summ -= b[i] - a[i] * idd
	if summ <= k:
		return True
	else:
		return False
while R - L != 1:
	mid = (L + R) / 2
	mid = int(mid)
	if check(mid) == True:
		L = mid
	else:
		R = mid
print(L)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = 0
while True:
	need = 0
	for i in range(n):
		if a[i] > b[i]:
			need += abs(b[i] - a[i])
			b[i] = 0
		else:
			b[i] -= a[i]
	if need > k:
		break
	else:
		k -= need
		c += 1
print(c)


def possible(List1, List2, l, k, n):
	s = 0
	for i in range(l):
		if n * List2[i] - List1[i] > 0:
			s += n * List2[i] - List1[i]
	if s <= k:
		return True
	else:
		return False
nk = list(map(int, input().rstrip().split()))
n = nk[0]
k = nk[1]
abc = list(map(int, input().rstrip().split()))
xyz = list(map(int, input().rstrip().split()))
minm = 0
maxm = 2000
while minm < maxm - 1:
	mid = (minm + maxm) // 2
	if possible(xyz, abc, n, k, mid):
		minm = mid
	else:
		maxm = mid - 1
else:
	if possible(xyz, abc, n, k, maxm):
		print(maxm)
	else:
		print(minm)


def magicPowder():
	(ingredients, mps) = map(int, input().split())
	need = [int(s) for s in input().split()]
	have = [int(s) for s in input().split()]
	low = 0
	high = 2000
	a = 0
	total = 0
	while low <= high:
		mid = low + (high - low) // 2
		for i in range(ingredients):
			if need[i] * mid >= have[i]:
				total += need[i] * mid - have[i]
		if total <= mps:
			low = mid + 1
			a = mid
		else:
			high = mid - 1
		total = 0
	print(a)
magicPowder()


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

def Possible(x):
	powder = k
	for i in range(n):
		cnt = B[i] // A[i]
		if cnt < x:
			powder -= A[i] * x - B[i]
			if powder < 0:
				return False
	return True
left = 0
right = 10 ** 9 + 10 ** 9 + 10
while left + 1 < right:
	mid = (left + right) // 2
	if Possible(mid):
		left = mid
	else:
		right = mid
print(left)


(n, k) = [int(x) for x in input().split()]
a = list(map(int, input().split()))
b = list(map(int, input().split()))
rat = []
for i in range(n):
	rat.append(b[i] // a[i])
ans = min(rat)
c = min(rat)
for i in range(n):
	b[i] -= a[i] * c
while k != 0:
	ch = 0
	for i in range(n):
		if b[i] < a[i]:
			k -= a[i] - b[i]
			b[i] = a[i]
			if k < 0:
				ch = 1
				break
	if ch == 0:
		ans -= -1
	else:
		break
	for i in range(n):
		b[i] -= a[i]
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = 0
while True:
	i = 0
	while i < n:
		if b[i] < a[i]:
			k -= a[i] - b[i]
			b[i] = 0
		else:
			b[i] -= a[i]
		i += 1
	if k < 0:
		break
	c += 1
print(c)


def main():
	from heapq import heapify, heappop, heappushpop
	(n, k) = map(int, input().split())
	if n == 1:
		(a, b) = (int(input()), int(input()))
		print((b + k) // a)
		return
	l = list(((b // a, a - b % a, a) for (a, b) in zip(map(int, input().split()), map(int, input().split()))))
	heapify(l)
	(b, r, a) = heappop(l)
	while k >= r:
		k -= r
		(b, r, a) = heappushpop(l, (b + 1, a, a))
	print(b)
main()


(n, mp) = list(map(int, input().split(' ')))
a_list = list(map(int, input().split(' ')))
b_list = list(map(int, input().split(' ')))

def bake(mp):
	minus = 0
	for i in range(n):
		b_list[i] -= a_list[i]
		if b_list[i] < 0:
			minus += b_list[i]
			b_list[i] = 0
	mp += minus
	if mp >= 0:
		return (1, mp)
	else:
		return (0, mp)

def init_bake():
	c = min([b // a for (a, b) in zip(a_list, b_list)])
	for i in range(n):
		b_list[i] -= a_list[i] * c
	return c
cookies = init_bake()
while True:
	(c, mp) = bake(mp)
	if c == 0:
		break
	cookies += c
print(cookies)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
l = 0
r = 10 ** 10
while r - l > 1:
	m = (r + l) // 2
	poroshok = 0
	for i in range(n):
		tr = A[i] * m - B[i]
		poroshok += max(tr, 0)
	if poroshok > k:
		r = m
	else:
		l = m
print(l)


def check(num, powder):
	req = []
	for i in range(len(a)):
		req.append(num * a[i])
	for i in range(len(a)):
		if b[i] < req[i]:
			diff = req[i] - b[i]
			if diff > powder:
				return 0
			else:
				powder -= diff
	return 1

def bin_search(l, r, magic):
	while l < r:
		mid = (l + r + 1) // 2
		if check(mid, magic):
			l = mid
		else:
			r = mid - 1
	return l
(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ans = bin_search(0, 10000000, k)
print(ans)


(n, k) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
ans = 0
while k >= 0:
	for i in range(n):
		l2[i] = l2[i] - l1[i]
		if l2[i] < 0:
			k = k + l2[i]
			l2[i] = 0
			if k < 0:
				break
	else:
		ans += 1
print(ans)


def f(x):
	L = k
	for i in range(n):
		if B[i] // A[i] < x:
			L = L - (A[i] * x - B[i])
	if L < 0:
		return True
	else:
		return False
p = input()
p = p.split()
n = int(p[0])
k = int(p[1])
A = []
B = []
p = input()
q = input()
p = p.split()
q = q.split()
for i in range(n):
	A.append(int(p[i]))
	B.append(int(q[i]))
left = 0
right = 2 * 10 ** 9
while left < right - 1:
	mid = (left + right) // 2
	if f(mid):
		right = mid
	else:
		left = mid
print(left)


def calc(x):
	c = 0
	for i in range(n):
		if b[i] >= a[i] * x:
			continue
		c += a[i] * x - b[i]
		if c > k:
			return 1
	return c > k
(n, k) = input().split()
n = int(n)
k = int(k)
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = 0
r = 1000000000000000
while l < r:
	mid = (l + r + 1) // 2
	if calc(mid):
		r = mid - 1
	else:
		l = mid
print(l)


import math
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
check = math.ceil((sum(b) + k) / sum(a))
(x, y) = (0, check)
while True:
	if x == y:
		break
	mid = math.ceil((x + y) / 2)
	c = 0
	for i in range(n):
		if a[i] * mid - b[i] > 0:
			c += a[i] * mid - b[i]
	if c - k > 0:
		y = mid - 1
	elif c - k < 0:
		x = mid
	else:
		x = mid
		break
print(x)


(m, n) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
val = 0
k = 0
while val <= n:
	k += 1
	for i in range(m):
		if b[i] >= a[i]:
			b[i] -= a[i]
		else:
			val += a[i] - b[i]
			b[i] = 0
print(k - 1)


def check(a, b, midd, k):
	ans1 = 0
	for i in range(n):
		if a[i] * midd <= b[i]:
			continue
		ans1 += midd * a[i] - b[i]
		if ans1 > k:
			return False
	return True
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = 0
r = 3 * 10 ** 9
ans = 0
while l <= r:
	mid = (l + r) // 2
	if check(a, b, mid, k):
		l = mid + 1
		ans = max(ans, mid)
	else:
		r = mid - 1
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
e = [b[i] // a[i] for i in range(n)]
d = [b[i] % a[i] for i in range(n)]
while k:
	i = e.index(min(e))
	mi = min(k, a[i] - d[i])
	d[i] += mi
	k -= mi
	e[i] += d[i] // a[i]
	d[i] %= a[i]
print(min(e))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
while k >= 0:
	ans += 1
	for i in range(n):
		b[i] -= a[i]
		if b[i] < 0:
			k += b[i]
			b[i] = 0
print(ans - 1)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
st = 0
end = 10 ** 9
ans = -1
while st <= end:
	mid = (st + end) // 2
	e = 0
	s = -k
	for i in range(n):
		t = b[i] - a[i] * mid
		if t < 0:
			s = s - t
	if s == 0:
		ans = mid
		break
		end = mid - 1
	elif s > 0:
		end = mid - 1
	else:
		st = mid + 1
if ans == -1:
	print(end)
else:
	print(ans)


(m, n) = map(int, input().split())
arr1 = input().split()
arr2 = input().split()
for i in range(len(arr1)):
	arr1[i] = int(arr1[i])
for k in range(len(arr2)):
	arr2[k] = int(arr2[k])

def check(p):
	missing = 0
	need = []
	for i in range(m):
		need.append(arr1[i] * p)
	for j in range(m):
		if need[j] > arr2[j]:
			missing = missing + (need[j] - arr2[j])
	if missing > n:
		return False
	return True

def binarysearch():
	lo = 0
	hi = 3000
	while lo <= hi:
		mid = (lo + hi) // 2
		if check(mid) == True:
			lo = mid + 1
			ans = mid
		elif check(mid) == False:
			hi = mid - 1
	return ans
print(binarysearch())


def gap(n, k, d, h, mid):
	total = k
	for i in range(n):
		if total >= max(0, d[i] * mid - h[i]):
			total -= max(0, d[i] * mid - h[i])
		else:
			return False
	return True

def binary_search(n, k, d, h):
	(l, r) = (0, int(2000000000.0))
	while l <= r:
		mid = l + r >> 1
		if gap(n, k, d, h, mid):
			l = mid + 1
		else:
			r = mid - 1
	return l - 1

def main():
	(n, k) = map(int, input().split())
	d = list(map(int, input().split()))
	h = list(map(int, input().split()))
	print(binary_search(n, k, d, h))
main()


(n, k) = map(int, input().split())
required = list(map(int, input().split()))
has = list(map(int, input().split()))
low = 0
high = 10 ** 10 + 10
ans = 0
while 1:
	powder = 0
	mid = (low + high) // 2
	ch = 1
	for i in range(n):
		if required[i] * mid > has[i]:
			powder += required[i] * mid - has[i]
		if powder > k:
			ch = 0
			break
	if ch:
		low = mid + 1
		if low > high:
			ans = high
			break
	else:
		high = mid - 1
		if low > high:
			ans = low
			break
print(high)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
S = 0
_min = b[0] // a[0]
for i in range(n):
	S += a[i]
	x = b[i] // a[i]
	if x < _min:
		_min = x
for i in range(n):
	b[i] -= a[i] * _min
cnt = _min
while True:
	need = S
	for i in range(n):
		if b[i] < a[i]:
			need -= b[i]
			b[i] = 0
		else:
			need -= a[i]
			b[i] -= a[i]
	if need < k:
		k -= need
		cnt += 1
	elif need == k:
		cnt += 1
		break
	else:
		break
print(cnt)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
left = 0
right = int(1000000000000000.0)
while right - left > 1:
	mid = (left + right) // 2
	ok = True
	cur = k
	for i in range(n):
		if b[i] // a[i] >= mid:
			continue
		if mid * a[i] - b[i] <= cur:
			cur -= mid * a[i] - b[i]
		else:
			ok = False
			break
	if ok == True:
		left = mid
	else:
		right = mid
if left > 1000000000000.0:
	print(0)
else:
	print(left)


(n, k) = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
r = 0
ok = 1
while ok:
	L = [0 for _ in range(n)]
	for i in range(n):
		B[i] = B[i] - A[i]
		if B[i] < 0:
			L[i] = -B[i]
			B[i] = 0
	if sum(L) <= k:
		r += 1
		k = k - sum(L)
	else:
		ok = 0
print(r)


import re
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
total_for_next_batch = sum(a)
divs = []
for_next = []
for i in range(n):
	divs.append(b[i] // a[i])
	for_next.append(a[i] - b[i] % a[i])
flag = True
while k > 0 and flag:
	min_cookies = min(divs)
	locations = [i for i in range(n) if divs[i] == min_cookies]
	for i in locations:
		if k >= for_next[i]:
			k -= for_next[i]
			for_next[i] = a[i]
			divs[i] += 1
		elif k < for_next[i]:
			flag = False
			break
print(min(divs))


(n, k) = list(map(int, input().split()))
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [b[i] // a[i] for i in range(n)]
d = [b[i] % a[i] for i in range(n)]
while k:
	i = c.index(min(c))
	m = min(k, a[i] - d[i])
	d[i] += m
	k -= m
	c[i] += d[i] // a[i]
	d[i] %= a[i]
print(min(c))


(n, k) = map(int, input().split())
b = list(map(int, input().split()))
a = list(map(int, input().split()))
c = []
x = 0
for i in range(n):
	c.append([a[i] // b[i], a[i], b[i]])
c.append([10 ** 12, 0, 10 ** 10])
c = sorted(c)
ans = c[0][0]
suma = 0
sumb = 0
i = 0
n += 1
while i < n:
	j = i
	cura = 0
	curb = 0
	while i < n and c[j][0] == c[i][0]:
		cura += c[i][1]
		curb += c[i][2]
		i += 1
	if sumb * c[j][0] - suma <= k:
		ans = max(ans, c[j][0])
	else:
		ans = max(ans, min((suma + k) // sumb, c[j][0] - 1))
		break
	suma += cura
	sumb += curb
print(ans)


import sys
f = sys.stdin.readline
(n, k) = map(int, f().strip().split())
a = [int(v) for v in f().strip().split()]
b = [int(v) for v in f().strip().split()]
l = 0
r = 10 ** 10

def check(val):
	global k, n
	k_ = 0
	for i in range(n):
		k_ += max(0, val * a[i] - b[i])
		if k_ > k:
			return False
	return True
while l < r:
	mid = l + r >> 1
	if check(mid):
		l = mid + 1
	else:
		r = mid
print(l - 1)


import sys
(n, k) = list(map(int, sys.stdin.readline().split()))
lst = list(map(int, sys.stdin.readline().split()))
ingr = list(map(int, sys.stdin.readline().split()))
ans = [[0, 0, 0] for i in range(n)]
for i in range(n):
	ans[i][0] = ingr[i] // lst[i]
	ans[i][1] = ingr[i] % lst[i]
	ans[i][2] = i
ans.sort(key=lambda x: [x[0], x[1]])
minn = ans[0][0]
while k > 0:
	ans[0][1] += 1
	k -= 1
	if ans[0][1] >= lst[ans[0][2]]:
		ans[0][0] += 1
		ans[0][1] = 0
	ans.sort(key=lambda x: [x[0], x[1]])
	if ans[0][0] > minn:
		minn = ans[0][0]
print(minn)


def minimum(l):
	min_value = l[0]
	min_index = 0
	for i in range(1, len(l)):
		if l[i] < min_value:
			min_value = l[i]
			min_index = i
	return (min_value, min_index)
(n, k) = [int(s) for s in input().split()]
needs = [int(s) for s in input().split()]
has = [int(s) for s in input().split()]
can_bake = [int(has[i] / needs[i]) for i in range(n)]
while k > 0:
	(min_value, min_index) = minimum(can_bake)
	has[min_index] += 1
	k -= 1
	can_bake[min_index] = int(has[min_index] / needs[min_index])
print(min(can_bake))


from math import ceil
(n, k) = map(int, input().split())
arr = []
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	x = ceil(b[i] / a[i])
	s = a[i] * x
	s = s - b[i]
	if s == 0:
		s = a[i]
	arr.append([b[i] // a[i], s, i])
while k > 0:
	x = min(arr, key=lambda x: (x[0], x[1]))
	if k >= x[1]:
		temp = x[0]
		x[0] += 1
		k -= x[1]
		x[1] = a[x[2]]
	else:
		break
print(min(arr, key=lambda x: x[0])[0])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = 0
while k >= 0:
	c = []
	p = []
	for i in range(len(a)):
		c.append(b[i] // a[i])
	o = min(c)
	l += o
	for i in range(len(b)):
		b[i] -= o * a[i]
	for i in range(len(b)):
		if a[i] > b[i]:
			k -= a[i] - b[i]
			b[i] = a[i]
print(l)


import math

def set_of_mins_and_rest(a, b):
	rest = [b[i] - a[i] * math.floor(b[i] / a[i]) - a[i] for i in range(len(a))]
	total = [math.floor(b[i] / a[i]) for i in range(len(a))]
	return (rest, total)

def get_need_k(b1, a1, tx):
	(rest, total) = set_of_mins_and_rest(a1, b1)
	pos_ax = [a1[i] * tx - b1[i] for i in range(len(a1)) if total[i] < tx]
	return sum(pos_ax)

def binary_search_mod(array, a1, b1, target):
	lower = 0
	upper = len(array)
	while lower < upper:
		x = lower + (upper - lower) // 2
		val = array[x]
		val = get_need_k(b1, a1, val)
		if target == val:
			return x
		elif target > val:
			if lower == x:
				break
			lower = x
		elif target < val:
			upper = x
	return x

def get_max_cakes(a, b, k):
	a1 = a[:]
	b1 = b[:]
	mp = k
	if mp > 0:
		(rest, total) = set_of_mins_and_rest(a1, b1)
		tmp = sorted(total)
		tx_tmp = tmp[binary_search_mod(tmp, a1, b1, mp)]
		sx_tmp = get_need_k(b1, a1, tx_tmp)
		if sx_tmp <= mp:
			mp -= sx_tmp
			b1 = [a1[i] * tx_tmp if total[i] < tx_tmp else b1[i] for i in range(len(a1))]
			(rest, total) = set_of_mins_and_rest(a1, b1)
		mn = min(total)
		pos_mn = [i for i in range(len(total)) if total[i] == mn]
		pos_mx = [rest[j] for j in pos_mn]
		mx = pos_mx
		sx = sum(pos_mx)
		if mp >= abs(sx):
			mp += sx
			mn += 1
			for t in range(len(pos_mn)):
				b1[pos_mn[t]] += abs(pos_mx[t])
			while mp > 0:
				(rest, total) = set_of_mins_and_rest(a1, b1)
				mn = min(total)
				tmp = sorted(total)
				pos_mn = [i for i in range(len(total)) if total[i] == mn]
				for i in range(len(tmp)):
					tx = 0
					if tmp[i] > mn:
						tx = tmp[i]
					else:
						continue
					(rest, total) = set_of_mins_and_rest(a1, b1)
					mn = min(total)
					tmp = sorted(total)
					pos_mn = [i for i in range(len(total)) if total[i] == mn]
					pos_ax = [a1[i] * tx - b1[i] for i in pos_mn]
					sx = sum(pos_ax)
					if sx <= mp:
						mp -= sx
						for i in pos_mn:
							b1[i] += a1[i] * tx - b1[i]
						(rest, total) = set_of_mins_and_rest(a1, b1)
						mn = min(total)
					else:
						pos_ax = [a1[i] for i in pos_mn]
						rest_ax = [-rest[i] for i in pos_mn]
						if sum(rest_ax) <= mp:
							sx = sum(rest_ax)
							mp -= sx
							return mn + 1 + int(mp / sum(pos_ax))
						else:
							return mn
				(rest, total) = set_of_mins_and_rest(a1, b1)
				pos_ax = [a1[i] for i in range(len(total))]
				rest_ax = [-rest[i] for i in range(len(total))]
				if sum(rest_ax) <= mp:
					sx = sum(rest_ax)
					mp -= sx
					return mn + 1 + int(mp / sum(pos_ax))
				else:
					return mn
	return mn
input_str = str(input())
t = [int(k) for k in input_str.split()]
(n, k) = (t[0], t[1])
input_str = str(input())
a = [int(k) for k in input_str.split()]
input_str = str(input())
b = [int(k) for k in input_str.split()]
print(get_max_cakes(a, b, k))


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [y // x for (x, y) in zip(a, b)]
mindex = c.index(min(c))
while k > 0:
	b[mindex] += 1
	c[mindex] = b[mindex] // a[mindex]
	k -= 1
	mindex = c.index(min(c))
print(min(c))


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict as dd, deque as dq
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	(N, K) = getInts()
	A = getInts()
	B = getInts()
	curr_min = 10 ** 10
	for i in range(N):
		curr_min = min(curr_min, B[i] // A[i])
	ans = curr_min
	rem = []
	for i in range(N):
		rem.append(B[i] - curr_min * A[i])

	def works(D):
		req = 0
		for i in range(N):
			req += max(0, D * A[i] - rem[i])
		return req <= K
	assert works(0)
	assert not works(10 ** 18)
	left = 0
	right = 10 ** 18
	while right - left > 1:
		mid = (right + left) // 2
		if works(mid):
			left = mid
		else:
			right = mid
	return ans + left
print(solve())


(n, k) = map(int, input().split())
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
ans = 0
while True:
	for i in range(n):
		if a[i] > b[i]:
			if k < a[i] - b[i]:
				print(ans)
				raise SystemExit
			k -= a[i] - b[i]
			b[i] = 0
		else:
			b[i] -= a[i]
	ans += 1


import sys, math
(n, k) = map(int, sys.stdin.readline().split())
need = list(map(int, sys.stdin.readline().split()))
have = list(map(int, sys.stdin.readline().split()))
l = 0
r = 10 ** 10
while l <= r:
	mid = (l + r) // 2
	x = 0
	for i in range(n):
		if mid * need[i] > have[i]:
			x += mid * need[i] - have[i]
	if x <= k:
		l = mid + 1
	else:
		r = mid - 1
print(l - 1)


class Ingred:

	def __init__(self, i, a, b):
		self.index = i
		self.needed = a
		self.given = b
		self.possbl = int(b / a)

	def __repr__(self):
		return '[' + str(self.needed) + ',' + str(self.given) + ',' + str(self.possbl) + ']'

def per(obj):
	return obj.possbl

def findIndex(x, arr):
	start = 0
	end = len(arr) - 1
	if arr[0].possbl >= x:
		return -1
	if arr[-1].possbl < x:
		return end
	while True:
		ind = int((start + end) / 2)
		if arr[ind].possbl < x:
			start = ind
			if ind < len(arr) - 1 and arr[ind + 1].possbl >= x:
				return ind
		else:
			end = ind
		if ind == len(arr) - 1:
			return ind

def xTimes(x, arr, needed, given, magic):
	ind = findIndex(x, arr)
	if ind == -1:
		return True
	deficit = needed[ind] * x - given[ind]
	if deficit > magic:
		return False
	return True
inf = list(map(int, input().split()))
n = inf[0]
k = inf[1]
temp = list(map(int, input().split()))
tmp = list(map(int, input().split()))
given = [0] * n
needed = [0] * n
array = [None] * n
for i in range(n):
	array[i] = Ingred(i, temp[i], tmp[i])
array = sorted(array, key=per)
for i in range(n):
	needed[i] = needed[i - 1] + array[i].needed
	given[i] = given[i - 1] + array[i].given
start = 0
end = 4000000009
x = start
dic = {}
while True:
	p = xTimes(x, array, needed, given, k)
	dic[x] = True
	if p:
		start = x
	else:
		end = x
	x = int((start + end) / 2)
	try:
		dic[x]
		break
	except:
		damn = 0
print(x)


R = lambda : map(int, input().split())
(n, k) = R()
(single, total) = (list(R()), list(R()))
while k:
	(mv, mi) = min([(t // s, i) for (i, (s, t)) in enumerate(zip(single, total))])
	total[mi] += 1
	k -= 1
print(min([t // s for (s, t) in zip(single, total)]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
backlog = {}
for i in range(n):
	if b[i] // a[i] in d:
		d[b[i] // a[i]] += a[i] - b[i] % a[i]
		backlog[b[i] // a[i]] += a[i]
	else:
		d[b[i] // a[i]] = a[i] - b[i] % a[i]
		backlog[b[i] // a[i]] = a[i]
special = list(backlog.keys())
special.sort()
prev = [0]
total = 0
for i in range(len(special)):
	total += backlog[special[i]]
	prev.append(total)
prev.append(0)
start = special[0]
ans = start
for keyz in range(special[0], special[-1]):
	if keyz not in d:
		d[keyz] = 0
i = special[0]
j = 0
save = 0
while k > 0 and j < len(special) and (i <= special[-1]):
	if d[i] > 0:
		if d[i] + prev[j] <= k:
			k -= d[i] + prev[j]
			save = prev[j + 1]
			ans += 1
			i += 1
			j += 1
		else:
			k = -1
	elif save <= k:
		k -= save
		ans += 1
		i += 1
	else:
		k = -1
if k > 0:
	ans += k // prev[-2]
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
while k > 0:
	mini = 10 ** 15
	minix = -1
	for i in range(n):
		if mini > b[i] // a[i]:
			mini = b[i] // a[i]
			minix = i
	b[minix] += 1
	k -= 1
mini = 10 ** 15
for i in range(n):
	if mini > b[i] // a[i]:
		mini = b[i] // a[i]
		minix = i
print(mini)


def check():
	global n, k, A, B
	a = k
	h = 0
	for i in range(n):
		if k < 0:
			h = 1
			break
		elif B[i] >= A[i]:
			B[i] -= A[i]
		elif B[i] + k < A[i]:
			h = 1
			break
		else:
			k -= A[i] - B[i]
			B[i] = 0
	if h == 1:
		return False
	else:
		return True
(n, k) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
p = 0
while check():
	p += 1
print(p)


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


import math

class codeforces:

	def holidays(self, n):
		ans = int(n / 7) * 2
		if n % 7 >= 2:
			max = ans + 2
		else:
			max = ans + n % 7
		if n % 7 > 5:
			min = ans + n % 7 - 5
		else:
			min = ans
		print(int(min), int(max))

	def robots(self, n, k, l):
		r = int((-1 + math.sqrt(1 + 8 * k)) / 2)
		temp = int(k - r * (r + 1) / 2)
		if temp == 0:
			print(l[r - 1])
		else:
			print(l[temp - 1])

	def magic(self, n, k, need, amt):
		for x in range(n):
			l = [int(amt[x] / need[x]) for x in range(n)]
		ans = min(l)
		for x in range(n):
			amt[x] = amt[x] - ans * need[x]
		temp = 0
		while temp <= k:
			temp = 0
			for x in range(n):
				if amt[x] < need[x]:
					temp += need[x] - amt[x]
			if k >= temp:
				ans += 1
				k -= temp
				for x in range(n):
					if amt[x] > need[x]:
						amt[x] -= need[x]
					else:
						amt[x] = 0
		print(ans)
s = codeforces()
d = [int(x) for x in input().split()]
n = d[0]
k = d[1]
need = [int(x) for x in input().split()]
amt = [int(x) for x in input().split()]
s.magic(n, k, need, amt)


from sys import stdin, stderr
from heapq import heappush, heappop

def readInts():
	return map(int, stdin.readline().strip().split())

def print_err(*args, **kwargs):
	print(*args, file=stderr, **kwargs)

def solve(n, k, a, b):
	h = []
	for ix in range(n):
		heappush(h, [b[ix] // a[ix], b[ix] % a[ix], a[ix]])
	for _ in range(k):
		p = heappop(h)
		p[1] += 1
		if p[1] == p[2]:
			p[0] += 1
			p[1] = 0
		heappush(h, p)
	return heappop(h)[0]

def run():
	(n, k) = readInts()
	a = list(readInts())
	b = list(readInts())
	print(solve(n, k, a, b))
run()


def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def MAP2():
	return map(float, input().split())

def LIST():
	return list(map(int, input().split()))

def STRING():
	return input()
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]

def solve(a, b, n, mp, midd):
	sm = 0
	for i in range(n):
		if midd * a[i] <= b[i]:
			continue
		sm += midd * a[i] - b[i]
		if sm > mp:
			return False
	return True
(n, mp) = MAP()
a = LIST()
b = LIST()
(l, r) = (0, 1000000009)
while l <= r:
	mid = l + (r - l) // 2
	z = solve(a, b, n, mp, mid)
	if z:
		l = mid + 1
	else:
		r = mid - 1
print(r)


def SolutionOne():
	ingredients = [int(x) for x in input().split()]
	magicPowder = ingredients[1]
	massNeeded = [int(x) for x in input().split()]
	massAvailable = [int(x) for x in input().split()]
	possibleAns = list(range(1, 100000))
	print(binarySearchMaxAns(possibleAns, massNeeded, massAvailable, magicPowder))

def checkValidAnswer(cookieNum, massNeeded, massAvailable, magicPowder):
	valid = True
	exceeds = []
	for (i, mass) in enumerate(massNeeded):
		if cookieNum * massNeeded[i] > massAvailable[i]:
			exceeds.append(cookieNum * massNeeded[i] - massAvailable[i])
		else:
			exceeds.append(0)
	if sum(exceeds) > magicPowder:
		valid = False
	return valid

def binarySearchMaxAns(answerArray, massNeeded, massAvailable, magicPowder):
	midpointIndex = len(answerArray) // 2
	midpoint = answerArray[midpointIndex]
	if len(answerArray) <= 1 and checkValidAnswer(answerArray[0], massNeeded, massAvailable, magicPowder) == False:
		return 0
	if len(answerArray) <= 1 and checkValidAnswer(answerArray[0], massNeeded, massAvailable, magicPowder) == True:
		return answerArray[0]
	if checkValidAnswer(midpoint, massNeeded, massAvailable, magicPowder) == False:
		return binarySearchMaxAns(answerArray[:midpointIndex], massNeeded, massAvailable, magicPowder)
	if checkValidAnswer(midpoint, massNeeded, massAvailable, magicPowder) == True:
		return binarySearchMaxAns(answerArray[midpointIndex:], massNeeded, massAvailable, magicPowder)
SolutionOne()


def distr(amt, k, n, a, b):
	for i in range(n):
		k -= max(0, a[i] * amt - b[i])
	return k
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [b[i] // a[i] for i in range(n)]
l = 0
r = 1000000000.0
ans = 0
while l <= r:
	mid = (l + r) // 2
	if distr(mid, k, n, a, b) < 0:
		r = mid - 1
	if distr(mid, k, n, a, b) >= 0:
		ans = max(ans, mid)
		l = mid + 1
print(int(ans))


import sys
(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(b)
batch = 0
while True:
	c = [c[i] - a[i] for i in range(0, n)]
	failed = False
	for i in range(0, n):
		if c[i] < 0:
			if k > -c[i]:
				k -= -c[i]
				c[i] = 0
			else:
				failed = True
				break
	if failed:
		break
	batch += 1
	for i in range(0, n):
		if c[i] < a[i]:
			if k >= a[i] - c[i]:
				k -= a[i] - c[i]
				c[i] = a[i]
			else:
				failed = True
	if failed:
		break
print(batch)


import math
(n, k) = input().split()
n = int(n)
k = int(k)
a = []
a = input().split()
b = input().split()
for i in range(n):
	(a[i], b[i]) = (int(a[i]), int(b[i]))
diff = 0
(s, l) = (0, 10 ** 15)
while s < l:
	diff = 0
	nset = math.ceil((s + l) / 2)
	for i in range(len(a)):
		if a[i] * nset - b[i] > 0:
			diff += a[i] * nset - b[i]
	if diff > k:
		l = nset - 1
	elif diff <= k:
		s = nset
print(s)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

def check(mid):
	left = 0
	for i in range(n):
		left += max(0, mid * a[i] - b[i])
	return left <= k

def binsearch(lo, hi):
	ans = int(-1e+18)
	while lo <= hi:
		mid = (lo + hi + 1) // 2
		if check(mid):
			ans = max(ans, mid)
			lo = mid + 1
		else:
			hi = mid - 1
	return ans
ans = binsearch(0, int(1e+18))
print(ans)


import sys

def enough(n, k, a, b, m):
	for i in range(n):
		k -= max(0, m * a[i] - b[i])
		if k < 0:
			return False
	return k >= 0

def binary_search(n, k, a, b):
	left = 0
	right = int(2000000000.0)
	while right - left > 1:
		middle = (left + right) // 2
		if enough(n, k, a, b, middle):
			left = middle
		else:
			right = middle
	if enough(n, k, a, b, right):
		return right
	else:
		return left
(n, k) = [int(i) for i in sys.stdin.readline().strip().split()]
a = [int(i) for i in sys.stdin.readline().strip().split()]
b = [int(i) for i in sys.stdin.readline().strip().split()]
print(binary_search(n, k, a, b))


def check(mid, k, a, b, n):
	need = 0
	for i in range(n):
		if a[i] * mid > b[i]:
			need += a[i] * mid - b[i]
	if need > k:
		return 0
	else:
		return 1
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = 0
r = 10000000000000000
while l <= r:
	mid = l + (r - l) // 2
	if check(mid, k, a, b, n):
		l = mid + 1
	else:
		r = mid - 1
if check(l, k, a, b, n):
	print(l)
else:
	print(r)


def can_make(a, b, k, n):
	k2 = k
	for (t, v) in zip(a, b):
		diff = v - t * n
		if diff < 0:
			k2 += diff
	return k2 >= 0

def main():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	lo = 0
	hi = 10 ** 15
	while lo + 1 < hi:
		mid = (lo + hi) // 2
		if can_make(a, b, k, mid):
			lo = mid
		else:
			hi = mid
	print(lo)
main()


(inger, magic) = input().split()
(inger, magic) = (int(inger), int(magic))
(needed, avail) = ([] * inger, [] * inger)
needed[:] = input().split()
avail[:] = input().split()
(condition, cookies, con) = (1, 0, 1)
while condition == 1:
	tester = []
	for i in range(0, inger):
		(needed[i], avail[i]) = (int(needed[i]), int(avail[i]))
		avail[i] = avail[i] - needed[i]
		if avail[i] < 0:
			tester.append(abs(avail[i]))
			avail[i] = 0
		else:
			tester.append(0)
	if tester.count(0) == len(tester):
		cookies = cookies + 1
	elif magic >= sum(tester):
		cookies = cookies + 1
		magic = magic - sum(tester)
	else:
		break
print(cookies)


from math import ceil, sqrt, gcd, log, floor
from collections import deque

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def li():
	return list(mi())

def msi():
	return map(str, input().strip().split(' '))

def lsi():
	return list(msi())
(n, k) = mi()
m = [0] * 1010
a = li()
b = li()
x = 0
s = sum(a)
for i in range(n):
	x = max(x, ceil(b[i] / a[i]))
for i in range(n):
	y = b[i] % a[i]
	x1 = a[i] - y
	m[b[i] // a[i] + 1] += x1
	x1 += a[i]
	for j in range(b[i] // a[i] + 2, x + 1):
		m[j] += x1
		x1 += a[i]
if k > max(m):
	x1 = m.index(max(m))
	k -= max(m)
	x1 += k // s
	print(x1)
else:
	x1 = 0
	f = 0
	for i in range(1001):
		if m[i] != 0:
			f = 1
		if m[i] > k:
			break
		if f == 1 and m[i] == 0:
			break
		x1 = i
	print(x1)


read = lambda : map(int, input().split())
(n, k) = read()
a = list(read())
b = list(read())
c = [0] * n
r = [0] * n
for i in range(n):
	c[i] = b[i] // a[i]
	r[i] = a[i] - b[i] % a[i]
while k:
	cur = min(c)
	i = c.index(min(c))
	if k >= r[i]:
		k -= r[i]
		c[i] += 1
		r[i] = a[i]
	else:
		break
ans = min(c)
print(ans)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(n):
	c.append(b[i] // a[i])
while k > 0:
	l = min(c)
	p = c.index(l)
	z = a[p] - b[p] % a[p]
	b[p] += min(z, k)
	k -= min(z, k)
	c[p] = b[p] // a[p]
print(min(c))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
kol = [b[i] // a[i] for i in range(n)]
ost = [b[i] % a[i] for i in range(n)]
ans = min(kol)
check = True
while check:
	check = False
	for i in range(n):
		if kol[i] == ans:
			if k >= a[i] - ost[i]:
				k -= a[i] - ost[i]
				ost[i] = 0
				kol[i] += 1
				check = True
	if check:
		ans = min(kol)
print(ans)


def process(key, a, b, k, n):
	res = False
	c = 0
	for i in range(n):
		y = b[i] - a[i] * key
		if b[i] - a[i] * key < 0:
			c += y
	k += c
	if k >= 0:
		res = True
	else:
		res = False
	return res

def bin_src(a, b, n, k, lo, hi):
	while hi - lo > 1:
		mid = (hi + lo) // 2
		val = process(mid, a, b, k, n)
		if val == True:
			lo = mid
		else:
			hi = mid
	if process(lo, a, b, k, n) == True:
		return lo
	else:
		return hi

def main():
	sol = []
	nk = list(map(int, input().split(' ')))
	(n, k) = (nk[0], nk[1])
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	sol.append(bin_src(a, b, n, k, 0, 10 ** 10))
	print(sol[0])
main()


def cout(k2, mid):
	for (x, y) in zip(a, b):
		if y + k2 < mid * x:
			return False
		elif y - mid * x < 0:
			k2 += y - mid * x
	return True
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(i, j) = (0, 0)
for (x, y) in zip(a, b):
	j = max(j, (y + k) // x)
while i + 1 < j:
	mid = (i + j) // 2
	k2 = k
	if cout(k2, mid) == True:
		i = mid
	else:
		j = mid
if cout(k, j) == True:
	print(j)
else:
	print(i)


from io import BytesIO, IOBase
from math import sqrt
import sys, os
from os import path
inpl = lambda : list(map(int, input().split()))
inpm = lambda : map(int, input().split())
inpi = lambda : int(input())
inp = lambda : input()
(rev, ra, l) = (reversed, range, len)
P = print
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def B(n):
	return bin(n).replace('0b', '')

def factors(n):
	arr = []
	for i in ra(2, int(sqrt(n)) + 1):
		if n % i == 0:
			arr.append(i)
			if i * i != n:
				arr.append(int(n / i))
	return arr

def dfs(arr, n):
	pairs = [[i + 1] for i in ra(n)]
	vis = [0] * (n + 1)
	for i in ra(l(arr)):
		pairs[arr[i][0] - 1].append(arr[i][1])
	pairs[arr[i][1] - 1].append(arr[i][0])
	comp = []
	for i in ra(n):
		stack = [pairs[i]]
		temp = []
		if vis[stack[-1][0]] == 0:
			while len(stack) > 0:
				if vis[stack[-1][0]] == 0:
					temp.append(stack[-1][0])
					vis[stack[-1][0]] = 1
					s = stack.pop()
					for j in s[1:]:
						if vis[j] == 0:
							stack.append(pairs[j - 1])
				else:
					stack.pop()
			comp.append(temp)
	return comp
from bisect import bisect_left as bl
from bisect import bisect_right as br
import sys, operator, math, operator
from collections import Counter
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
import random, heapq
(n, k) = inpm()
(li1, li2) = (inpl(), inpl())
heap = []
for i in ra(n):
	heap.append([li2[i] // li1[i], i])
heapq.heapify(heap)
while k > 0:
	p = heapq.heappop(heap)
	(a, b) = p
	if li2[b] % li1[b] == 0:
		li2[b] += min(li1[b], k)
		k -= min(li1[b], k)
		heapq.heappush(heap, [li2[b] // li1[b], b])
	else:
		rem = li1[b] - li2[b] % li1[b]
		li2[b] += min(rem, k)
		k -= min(rem, k)
		heapq.heappush(heap, [li2[b] // li1[b], b])
ans = heapq.heappop(heap)
P(int(ans[0]))


(n, k) = [int(x) for x in input().split(' ')]
need = [int(x) for x in input().split(' ')]
est = [int(x) for x in input().split(' ')]
a = 0
b = 10 ** 10
while b - a > 1:
	t = (a + b) // 2
	nu = 0
	for i in range(n):
		nu += 0 if need[i] * t <= est[i] else need[i] * t - est[i]
	if nu <= k:
		a = t
	else:
		b = t
nu = 0
for i in range(n):
	nu += 0 if need[i] * b <= est[i] else need[i] * b - est[i]
if nu <= k:
	print(b)
else:
	print(a)


(n, k) = list(map(int, input().split()))
req = list(map(int, input().split()))
avail = list(map(int, input().split()))
rem = []
used = []
for i in range(n):
	rem.append(avail[i] % req[i])
	used.append(avail[i] // req[i])
x = min(used)
for i in range(n):
	rem[i] += (used[i] - x) * req[i]
	used[i] = x
ans = x
while k:
	f = 0
	for i in range(n):
		if rem[i] >= req[i]:
			rem[i] -= req[i]
		elif rem[i] + k >= req[i]:
			k -= req[i] - rem[i]
			rem[i] = 0
		else:
			f = 1
			break
	if f == 0:
		ans += 1
	else:
		break
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

def check(c):
	global k
	global a
	global b
	dem = k
	for x in range(n):
		if b[x] >= a[x] * c:
			continue
		elif dem >= a[x] * c - b[x]:
			dem -= a[x] * c - b[x]
		else:
			return 0
	return 1
	pass
l = 0
r = 1000000007
while r - l > 1:
	mid = (r + l) // 2
	if check(mid):
		l = mid
	else:
		r = mid
print(l)


import math
(n, k) = map(int, input().split())
recipe = [int(z) for z in input().split()]
inventory = [int(z) for z in input().split()]
m = 0
for i in range(n):
	m = max(m, math.ceil((inventory[i] + k) // recipe[i]))
onecookie = sum(recipe)
ans = 0
left = 0
right = m + 1
oldc = 0
while left <= right:
	kneeded = 0
	c = (left + right) // 2
	if oldc == c:
		print(c)
		exit()
	for i in range(n):
		kneeded += max(0, recipe[i] * c - inventory[i])
	if kneeded == k:
		break
	elif kneeded > k:
		right = c
	elif kneeded < k:
		left = c
	oldc = c
print(c)


import sys
a = []
b = []
l = 0
val = 0
(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
while k > 0:
	val = 0
	for i in range(n):
		if a[i] <= b[i]:
			b[i] -= a[i]
		else:
			val = val + a[i] - b[i]
			b[i] = 0
	if val <= k:
		l += 1
	k -= val
print(l)


(ingredients, magic_grams) = map(int, input().split())
needed = list(map(int, input().split()))
available = list(map(int, input().split()))
factors = []
remainder = []
module = []
summation = 0
for i in range(ingredients):
	factors.append(int(available[i] / needed[i]))
	module.append(available[i] % needed[i])
	remainder.append(needed[i] - module[i])
	summation = summation + needed[i]
while min(factors) != max(factors):
	ind = factors.index(min(factors))
	if magic_grams >= remainder[ind]:
		magic_grams = magic_grams - remainder[ind]
		remainder[ind] = needed[ind]
		factors[ind] = factors[ind] + 1
		module[ind] = 0
	else:
		break
count = min(factors)
if module.count(0) != ingredients:
	rem = 0
	for i in range(ingredients):
		rem = rem + needed[i] - module[i]
	if magic_grams >= rem:
		count = factors[0] + 1
		magic_grams = magic_grams - rem
count = count + int(magic_grams / summation)
print(count)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
results = [None] * n
for i in range(n):
	(div, mod) = (b[i] // a[i], b[i] % a[i])
	insufficient = a[i] - mod
	results[i] = [div, mod, insufficient, i]
results.sort()
i = 0
while k > 0:
	k -= 1
	index = results[i][3]
	new_insufficient = results[i][2] - 1
	if new_insufficient == 0:
		results[i][0] += 1
		results[i][1] = 0
		results[i][2] = a[index]
	else:
		results[i][1] += 1
		results[i][2] -= 1
	results.sort()
print(results[0][0])


ax = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
result = 0
val = 0
xz = True
while xz:
	for x in range(ax[0]):
		if a[x] > b[x]:
			val += a[x] - b[x]
			b[x] = 0
		else:
			b[x] -= a[x]
	if val <= ax[1]:
		result += 1
		continue
	else:
		break
print(result)


(n, k) = map(int, input().split())
a = map(int, input().split())
b = map(int, input().split())
c = list(zip(a, b))
c.sort(key=lambda x: x[1] // x[0])
i = 0
count = c[0][1] // c[0][0]
part = 0
full = 0
while k > 0 and i < n:
	if count < c[i][1] // c[i][0]:
		if k > part:
			k -= part
			part = 0
			count += 1
			dco = min(c[i][1] // c[i][0] - count, k // full)
			count += dco
			k -= dco * full
			part = full + c[i][0] - c[i][1] % c[i][0]
			full += c[i][0]
		else:
			break
	else:
		part += c[i][0] - c[i][1] % c[i][0]
		full += c[i][0]
	i += 1
if k > part:
	count += 1
	k -= part
count += k // full
print(count)


from sys import stdin, stdout
(n, k) = map(int, stdin.readline().split())
no = list(map(int, stdin.readline().split()))
yes = list(map(int, stdin.readline().split()))
mn = float('inf')
for i in range(n):
	mn = min(mn, yes[i] // no[i])
cnt = mn
while k > 0:
	for i in range(n):
		if yes[i] // no[i] == mn:
			k -= no[i] * (mn + 1) - yes[i]
			yes[i] = no[i] * (mn + 1)
	if k >= 0:
		cnt += 1
		mn += 1
stdout.write(str(cnt))


def ok(x):
	need = sum([max(0, a[i] * x - b[i]) for i in range(n)])
	return need <= k
(n, k) = (int(_) for _ in input().split())
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
(lo, hi) = (0, 2 * 10 ** 9)
while lo <= hi:
	mid = lo + hi >> 1
	if ok(mid):
		lo = mid + 1
	else:
		hi = mid - 1
print(hi)


def can(x):
	k1 = k
	for (ai, bi) in zip(a, b):
		if bi + k1 < ai * x:
			return False
		k1 -= max(0, ai * x - bi)
	return True
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
r = -1
lo = 0
hi = 2001
while lo < hi:
	mi = (lo + hi) // 2
	if can(mi):
		r = max(r, mi)
		lo = mi + 1
	else:
		hi = mi
print(r)


(n, k) = input().split(' ')
(n, k) = [int(n), int(k)]
list1 = list(map(int, input().split(' ')))
list2 = list(map(int, input().split(' ')))
low = 0
high = 2000
while low < high:
	if high - low % 2 != 0:
		mid = low + (high - low) // 2 + 1
	else:
		mid = low + (high - low) // 2
	d = k
	list6 = []
	for i in range(n):
		if list1[i] * mid <= list2[i]:
			list6.append(1)
		else:
			list6.append(0)
	for i in range(n):
		if list6[i] == 0:
			c = list1[i] * mid - list2[i]
			if d >= c:
				list6[i] = 1
				d = d - c
	for i in range(n):
		if list6[i] == 1:
			continue
		else:
			high = mid - 1
			break
	if high != mid - 1:
		low = mid
print(low)


import math
(n, k) = map(int, input().split())
req_ingr = list(map(int, input().split()))
hvng_ingr = list(map(int, input().split()))

def if_sum_bigger(count):
	summ = 0
	for i in range(n):
		summ += max(0, count * req_ingr[i] - hvng_ingr[i])
	if summ <= k:
		return True
	else:
		return False
l = 0
r = 2 * 10 ** 9 + 1
while r > l:
	m = math.floor((r + l) / 2)
	if if_sum_bigger(m):
		l = m + 1
	else:
		r = m
m = math.floor((r + l) / 2)
if if_sum_bigger(m):
	print(m)
else:
	print(m - 1)


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
min_c = float('inf')
for (x, y) in zip(a, b):
	min_c = min(min_c, y // x)
k2 = k
while k2 >= 0:
	k2 = k
	min_c += 1
	for (x, y) in zip(a, b):
		k2 -= max(x * min_c - y, 0)
print(min_c - 1)


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())
import sys
sys.setrecursionlimit(1000000000)

def check(md, x):
	for i in range(n):
		if la[i] * md > lb[i]:
			if x < la[i] * md - lb[i]:
				return False
			else:
				x = x - (la[i] * md - lb[i])
	return True
mxa = -1
(n, k) = f()
la = il()
lb = il()
l = 0
r = 10 ** 18 + 1
while l <= r:
	md = l + (r - l) // 2
	x = k
	if check(md, x):
		mxa = md
		l = md + 1
	else:
		r = md - 1
print(mxa)


from sys import *
from math import *
from bisect import *
(n, k) = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
b = list(map(int, stdin.readline().split()))

def fun(m):
	x = 0
	for i in range(n):
		if a[i] * m > b[i]:
			x += a[i] * m - b[i]
	if x <= k:
		return 1
	else:
		return 0
l = 0
h = 10 ** 18
ans = 0
while l <= h:
	m = (l + h) // 2
	if fun(m):
		l = m + 1
		ans = m
	else:
		h = m - 1
print(ans)


def f(c, k, a, b):
	u = 0
	for i in range(len(a)):
		r = a[i] * c
		if r > b[i]:
			u += r - b[i]
	if u <= k:
		return True
	else:
		return False
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(mi, ma) = (10 ** 18, 0)
for i in range(len(a)):
	(mi, ma) = (min(mi, b[i] // a[i]), max(ma, b[i] // a[i]))
(low, high, ans) = (0, 10 ** 18, 0)
while low <= high:
	mid = low + (high - low) // 2
	x = f(mid, k, a, b)
	if x:
		ans = max(ans, mid)
		low = mid + 1
	else:
		high = mid - 1
print(ans)


nums = [int(i) for i in input().split(' ')]
n = nums[0]
k = nums[1]
aln = [int(i) for i in input().split(' ')]
bln = [int(i) for i in input().split(' ')]
for i in range(0, k + 1):
	ind = 0
	alm = 0
	nm = 10000000000
	nm = 10000000000
	for j in range(0, len(aln)):
		if bln[j] // aln[j] < nm:
			nm = bln[j] // aln[j]
			ind = j
		elif bln[j] // aln[j] == nm:
			if aln[j] < alm:
				ind = j
				alm = aln[j]
	bln[ind] += 1
print(nm)


def main():

	def is_answer(ans):
		need = 0
		for i in range(n):
			need += max(0, a[i] * ans - b[i])
		return need <= k
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	left = 0
	right = 10 ** 18
	while right - left > 1:
		middle = (left + right) // 2
		if is_answer(middle):
			left = middle
		else:
			right = middle
	print(left)
main()


import sys
import math
import bisect

def query_value(A, B, k):
	n = len(A)
	ans = 0
	for i in range(n):
		if B[i] < A[i] * k:
			ans += A[i] * k - B[i]
	return ans

def solve(A, B, m):
	left = 0
	right = 1
	while query_value(A, B, right) <= m:
		right <<= 1
	while right - left > 1:
		mid = (left + right) // 2
		if query_value(A, B, mid) <= m:
			left = mid
		else:
			right = mid
	return left

def main():
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	ans = solve(A, B, m)
	print(ans)
main()


import sys
sys.stderr = sys.stdout

def cookies(n, k, A, B):

	def cfn(a, b):
		(q, r) = divmod(b, a)
		return (q, a - r, a)
	L = sorted((cfn(A[i], B[i]) for i in range(n)))
	c = 0
	p = 0
	q = 0
	for (ci, pi, ai) in L:
		if ci == c:
			p += pi
			q += ai
			continue
		if p > k:
			return c
		k -= p
		c += 1
		dk = q * (ci - c)
		if dk >= k:
			c += k // q
			return c
		k -= dk
		c = ci
		p = q + pi
		q += ai
	if p > k:
		return c
	k -= p
	c += 1
	c += k // q
	return c

def main():
	(n, k) = readinti()
	A = readintl()
	B = readintl()
	print(cookies(n, k, A, B))

def readint():
	return int(input())

def readinti():
	return map(int, input().split())

def readintt():
	return tuple(readinti())

def readintl():
	return list(readinti())

def readinttl(k):
	return [readintt() for _ in range(k)]

def readintll(k):
	return [readintl() for _ in range(k)]

def log(*args, **kwargs):
	print(*args, **kwargs, file=sys.__stderr__)
main()


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

def bs(m):
	c = 0
	for i in range(n):
		if a[i] * m > b[i]:
			c += abs(b[i] - a[i] * m)
	if c <= k:
		return True
	else:
		return False
(l, h) = (0, 10 ** 10)
ans = 0
while l <= h:
	m = l + (h - l) // 2
	if bs(m):
		ans = m
		l = m + 1
	else:
		h = m - 1
print(ans)


def is_possible(a, b, k, target):
	for (x, y) in zip(a, b):
		req = x * target
		avi = y
		if req > avi:
			k = k - (req - avi)
			if k < 0:
				return False
	return True
f = lambda : list(map(int, input().split()))

def search(a, b, k, low=0, high=10 ** 10):
	while low < high - 1:
		mid = (low + high) // 2
		r = is_possible(a, b, k, mid)
		if r:
			low = mid
		else:
			high = mid - 1
	if is_possible(a, b, k, low + 1):
		return low + 1
	return low
(n, k) = f()
a = f()
b = f()
k = search(a, b, k)
print(k)


(n, k) = map(int, input().split())
need = list(map(int, input().split()))
have = list(map(int, input().split()))
res = float('inf')
for i in range(n):
	res = min(res, have[i] // need[i])
for i in range(n):
	have[i] -= need[i] * res
while k:
	for i in range(n):
		diff = need[i] - have[i]
		if diff > 0:
			if k >= diff:
				k -= diff
				have[i] = 0
			else:
				k = 0
				break
		else:
			have[i] -= need[i]
	else:
		res += 1
print(res)


def f(x):
	k1 = k
	for i in range(n):
		if c[i] >= x:
			continue
		k1 -= (x - c[i] - 1) * a[i] + r[i]
		if k1 < 0:
			return False
	return True
read = lambda : map(int, input().split())
(n, k) = read()
a = list(read())
b = list(read())
(c, r) = ([0] * n, [0] * n)
for i in range(n):
	c[i] = b[i] // a[i]
	r[i] = a[i] - b[i] % a[i]
(L, R) = (0, 10 ** 10)
while R - L > 1:
	M = (L + R) // 2
	if f(M):
		L = M
	else:
		R = M
ans = L
print(ans)


import sys
(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
cookies = sys.maxsize
c = []
for i in range(n):
	cookies = min(cookies, b[i] // a[i])
	c.append([b[i] // a[i], b[i] % a[i], a[i]])
for i in range(n):
	c[i][0] -= cookies
c.sort()
flag = True
cnt = 0
while flag:
	for i in range(n):
		if c[i][0] - cnt == 0:
			if k >= c[i][2] - c[i][1]:
				k -= c[i][2] - c[i][1]
				c[i][1] = 0
				c[i][0] += 1
			else:
				flag = False
				break
		else:
			break
	if flag:
		cookies += 1
		cnt += 1
print(cookies)


args = input().split(' ')
n = int(args[0])
k = int(args[1])
tk = k
a = input().split(' ')
b = input().split(' ')
for i in range(0, n):
	a[i] = int(a[i])
	b[i] = int(b[i])
cmin = 0
cmax = 2000000000 + 1
while cmin + 1 != cmax:
	mid = cmin + (cmax - cmin) // 2
	for i in range(0, n):
		if mid * a[i] <= b[i]:
			cant = False
		elif mid * a[i] <= b[i] + k:
			k = k - (mid * a[i] - b[i])
			cant = False
		else:
			cant = True
			break
	k = tk
	if cant is True:
		cmax = mid
	else:
		cmin = mid
print(cmin)


def mul(L, x):
	m = []
	for y in L:
		m += [x * y]
	return m

def diff(a, b):
	d = 0
	for (i, j) in zip(a, b):
		d += j - i if j - i < 0 else 0
	return d
(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
high = 2001
low = 0
while low <= high:
	mid = (low + high) // 2
	d = diff(mul(a, mid), b)
	here = False
	if k + d == 0:
		break
	elif k + d < 0:
		here = True
		high = mid - 1
	else:
		low = mid + 1
print(mid if not here else high)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
g = [i // j for (i, j) in zip(b, a)]
s = sum(a)
l = min(g) + k // s
u = max(g) + k // s + 2

def f(k, x):
	for (i, j) in zip(b, a):
		deff = i - j * x
		if deff < 0:
			k += deff
			if k < 0:
				return False
	return True
while l + 1 < u:
	m = (l + u) // 2
	if f(k, m):
		l = m
	else:
		u = m
print(int(l))


from collections import deque
from math import *
from itertools import accumulate
import os
import sys
from io import BytesIO, IOBase
import math
import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def good(mid, a, b, k):
	for i in range(0, len(b)):
		if b[i] - a[i] * mid < 0:
			if b[i] + k - a[i] * mid >= 0:
				diff = a[i] * mid - b[i]
				k -= diff
			else:
				return False
	return True
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = 0
ans = 0
r = 10 ** 6
while l <= r:
	mid = (l + r) // 2
	if good(mid, a, b, k) == True:
		ans = mid
		l = mid + 1
	else:
		r = mid - 1
print(ans)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

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

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

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest
INF = 99999999999999999999999999999999

def outIn(x):
	print(x, flush=True)
	return input()

def main():
	mod = 1000000007
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	for _ in range(tc):
		(n, k) = ria()
		a = ria()
		b = ria()
		count = 0
		while True:
			for i in range(n):
				if b[i] >= a[i]:
					b[i] -= a[i]
				else:
					k -= a[i] - b[i]
					b[i] = 0
			if k >= 0:
				count += 1
			else:
				break
		wi(count)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


(i, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

def bs():
	l = 0
	r = 3000
	ans = 0
	while l <= r:
		mid = (l + r) // 2
		c = []
		need = 0
		for x in a:
			c.append(x * mid)
		for y in range(i):
			if b[y] < c[y]:
				need += c[y] - b[y]
		if k >= need:
			ans = mid
			l = mid + 1
		else:
			r = mid - 1
	print(ans)
bs()


(n, k) = map(int, input().split())
(a, b) = (list(map(int, input().split())), list(map(int, input().split())))
c = 0
while True:
	m = 0
	for i in range(n):
		if a[i] <= b[i]:
			m += 1
			b[i] -= a[i]
		elif a[i] <= k + b[i]:
			m += 1
			k -= a[i] - b[i]
			b[i] = 0
	if m == n:
		c += 1
	else:
		break
print(c)


def I():
	return list(map(int, input().split()))
(n, k) = I()
a = I()
b = I()
l = 0
r = 2 * 10 ** 9 + 1
while l < r - 1:
	m = (l + r) // 2
	s = 0
	for i in range(n):
		s += max(m * a[i] - b[i], 0)
	if s > k:
		r = m
	else:
		l = m
print(l)


(n, magic) = list(map(int, input().split()))
gramNeed = list(map(int, input().split()))
gramHas = list(map(int, input().split()))
able = []
remain = []
for i in range(n):
	able.append([gramHas[i] // gramNeed[i], gramHas[i] % gramNeed[i], gramNeed[i]])
able.sort(key=lambda x: x[0])
ans = able[0][0]
for i in range(n):
	able[i][0] -= ans
while magic > 0:
	i = 0
	for i in range(n):
		if able[i][0] == 0:
			able[i][1] += 1
			magic -= 1
			if able[i][1] == able[i][2]:
				able[i][0] += 1
				able[i][1] = 0
			break
	if min(able, key=lambda x: x[0])[0] != 0:
		ans += 1
		for i in range(n):
			able[i][0] -= 1
print(ans)


(n, s) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

def func(k):
	ans = s
	for i in range(n):
		temp = a[i] * k - b[i]
		if temp >= 0:
			ans = ans - temp
		if ans < 0:
			return False
	return True
(low, high) = (0, max([b[i] // a[i] for i in range(n)]) + s)
fin = 0
while low <= high:
	mid = (low + high) // 2
	check = func(mid)
	if check:
		fin = mid
		low = mid + 1
	else:
		high = mid - 1
print(fin)


(n, k) = [int(f) for f in input().split(' ') if f]
a = [int(f) for f in input().split(' ') if f]
b = [int(f) for f in input().split(' ') if f]
l = 0
r = 10000000000000
while l + 1 < r:
	mid = (l + r) // 2
	dust = int(k)
	for i in range(n):
		dust -= max(0, mid * a[i] - b[i])
		if dust < 0:
			break
	if dust < 0:
		r = mid
	else:
		l = mid
print(l)


class Solution:

	def getList(self):
		return list(map(int, input().split()))

	def solve(self):
		(n, k) = input().split()
		n = int(n)
		k = int(k)
		a = self.getList()
		b = self.getList()
		c = [b[i] // a[i] for i in range(n)]
		total = min(c)
		left = [b[i] - total * a[i] for i in range(n)]
		while True:
			required = 0
			for i in range(n):
				if left[i] >= a[i]:
					left[i] -= a[i]
				else:
					required += a[i] - left[i]
					left[i] = 0
			if required <= k:
				k -= required
				total += 1
			else:
				break
		print(total)
x = Solution()
x.solve()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [b[i] // a[i] for i in range(n)]
c1 = [b[i] % a[i] for i in range(n)]
while k > 0:
	x = min(c)
	ind = c.index(x)
	b[ind] += 1
	k -= 1
	c[ind] = b[ind] // a[ind]
	c1[ind] = b[ind] % a[ind]
print(min(c))


def foo(a, b):
	return int(int(b) / int(a))
a = input().split()
b = input().split()
c = input().split()
num = map(foo, b, c)
min = min(num)

def jian(a, b):
	global min
	return -int(a) * min + int(b)

def jiahe(li):
	nu = 0
	for i in li:
		if i <= 0:
			nu += i
	return nu
while True:
	shengxia = map(jian, b, c)
	shengxia = list(shengxia)
	if jiahe(shengxia) < -int(a[1]):
		break
	min += 1
print(min - 1)


(n, k) = map(int, input().split())
ll1 = list(map(int, input().split()))
ll2 = list(map(int, input().split()))
j = 0
lll = 0
while k > 0:
	for i in range(n):
		if ll2[i] >= ll1[i]:
			ll2[i] -= ll1[i]
		else:
			lll = lll + ll1[i] - ll2[i]
			ll2[i] = 0
	if lll <= k:
		j += 1
		k -= lll
		lll = 0
	else:
		break
print(j)


def check(arg):
	need = 0
	for i in range(n):
		need += max(arg * a[i] - b[i], 0)
	return need <= k
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
left = 0
right = 10 ** 10
while left + 1 < right:
	mid = (left + right) // 2
	if check(mid):
		left = mid
	else:
		right = mid
if check(right):
	print(right)
else:
	print(left)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
lo = 0
hi = 2 * 1000000000.0

def p(cookies):
	powder = k
	for i in range(len(b)):
		have = b[i]
		one = a[i]
		remainder = have - one * cookies
		if remainder < 0:
			powder += remainder
	if powder >= 0:
		return True
	return False
while lo < hi:
	m = (lo + hi) // 2
	if p(m):
		lo = m + 1
	else:
		hi = m
print(int(lo if p(lo) else lo - 1))


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]

def canMake(x):
	needed = [x * i for i in quantity]
	powder = magic
	for i in range(n):
		powder -= max(0, needed[i] - have[i])
		if powder < 0:
			return False
	return True
(n, magic) = value()
quantity = array()
have = array()
low = 0
high = 10 ** 15
ans = 0
while low <= high:
	mid = (low + high) // 2
	if canMake(mid):
		ans = mid
		low = mid + 1
	else:
		high = mid - 1
print(ans)


(n, k) = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ')]
b = [int(x) for x in input().split(' ')]
l = 0
r = 2 * 10000000000.0
while l < r:
	mid = (l + r) // 2 + 1
	sm = sum([max([a[i] * mid - b[i], 0]) for i in range(n)])
	if sm > k:
		r = mid - 1
	else:
		l = mid
print(int(l))


(n, k) = map(int, input().split())
need = list(map(int, input().split()))
have = list(map(int, input().split()))
get = [have[i] // need[i] for i in range(n)]
total = min(get)
left = [have[i] - total * need[i] for i in range(n)]
br = False
while True:
	requ = 0
	for i in range(n):
		if left[i] >= need[i]:
			left[i] -= need[i]
		else:
			want = need[i] - left[i]
			requ += want
			left[i] = 0
	if requ <= k:
		k -= requ
		total += 1
	else:
		break
print(total)


(N, K) = map(int, input().split())
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]
l = 1
r = max(B) * K + 1
ans = 0
while l <= r:
	temp = K
	mid = (l + r) // 2
	for i in range(N):
		if B[i] < mid * A[i]:
			temp -= mid * A[i] - B[i]
	if temp < 0:
		r = mid - 1
	else:
		ans = mid
		l = mid + 1
print(ans)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = []
r = []
for i in range(n):
	l.append([int(b[i] / a[i]), a[i]])
	r.append([b[i] % a[i], int(b[i] / a[i])])
l = sorted(l, key=lambda x: x[0])
r = sorted(r, key=lambda x: x[1])
p = k // sum(a)
t = 0
indice = 0
for i in range(n - 1):
	if l[i + 1][0] > l[i][0]:
		for j in range(indice, i + 1):
			t += l[j][1]
		e = min(l[i + 1][0] - l[i][0], int(k / t))
		if e == 0:
			break
		else:
			for j in range(0, i + 1):
				l[j][0] += e
			k -= e * t
		indice = j + 1
indice = 0
t = 0
for i in range(n - 1):
	if l[i + 1][0] > l[i][0]:
		for j in range(indice, i + 1):
			t += l[j][1] - r[j][0]
		if t <= k:
			for j in range(0, i + 1):
				l[j][0] += 1
				r[j][1] = 0
			k -= t
		else:
			break
		indice = j + 1
p = k // sum(a)
print(p + l[0][0])


import sys, math, bisect
sys.setrecursionlimit(10 ** 5)
from random import randint
inf = float('inf')
mod = 10 ** 9 + 7

def lcm(a, b):
	return int(a / math.gcd(a, b) * b)

def gcd(a, b):
	return int(math.gcd(a, b))

def tobinary(n):
	return bin(n)[2:]

def binarySearch(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1

def lowerBound(a, x):
	i = bisect.bisect_left(a, x)
	if i:
		return i - 1
	else:
		return -1

def upperBound(a, x):
	i = bisect.bisect_right(a, x)
	if i != len(a) + 1 and a[i - 1] == x:
		return i - 1
	else:
		return -1

def primesInRange(n):
	ans = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			ans.append(p)
	return ans

def primeFactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n = n // i
	if n > 2:
		factors.append(n)
	return factors

def isPrime(n, k=5):
	if n < 2:
		return True
	for i in range(0, k):
		a = randint(1, n - 1)
		if pow(a, n - 1, n) != 1:
			return False
	return True
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop, heapify
import string
for _ in range(1):
	(n, k) = map(int, input().split())
	need = list(map(int, input().split()))
	have = list(map(int, input().split()))

	def canMake(need, have, toMake, k):
		req = 0
		for i in range(len(need)):
			if need[i] * toMake <= have[i]:
				pass
			else:
				req += need[i] * toMake - have[i]
		if req <= k:
			return True
		return False
	ans = 0
	l = 1
	r = 10 ** 9
	while l <= r:
		mid = (l + r) // 2
		if canMake(need, have, mid, k):
			l = mid + 1
			ans = max(ans, mid)
		else:
			r = mid - 1
	print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(l, r) = (0, 2000000001)
ans = -1
while l <= r:
	mid = (l + r) // 2
	s = 0
	for i in range(n):
		if b[i] < mid * a[i]:
			s += mid * a[i] - b[i]
		if s > k:
			break
	if s > k:
		r = mid - 1
	elif s == k:
		ans = mid
		break
	else:
		l = mid + 1
if ans == -1:
	ans = l - 1
print(ans)


(n, k) = map(int, input().split())
r = list(map(int, input().split()))
a = list(map(int, input().split()))
c = []
for i in range(len(a)):
	c.append(a[i] // r[i])
total = min(c)
rn = 0
for i in range(len(a)):
	a[i] -= r[i] * total
	rn = rn if a[i] >= r[i] else rn + r[i] - a[i]
while k >= rn:
	total += 1
	rn2 = 0
	k -= rn
	for i in range(len(a)):
		a[i] = 0 if a[i] < r[i] else a[i] - r[i]
		rn2 = rn2 if a[i] >= r[i] else rn2 + r[i] - a[i]
	rn = rn2
print(total)


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

def fun(k):
	mag = m
	for i in range(0, n):
		if b[i] / a[i] < k:
			mag -= a[i] * k - b[i]
	if mag < 0:
		return 0
	else:
		return 1

def bin_sear(l, h):
	while h - l > 1:
		m = (h + l) // 2
		if fun(m):
			l = m
		else:
			h = m
	print(l)
maxi = 0
mini = float('inf')
for i in range(0, n):
	maxi = max(maxi, (b[i] + m) // a[i])
	mini = min(mini, b[i] // a[i])
bin_sear(mini, maxi + 1)