The term of this problem is the same as the previous one, the only exception — increased restrictions.


-----Input-----

The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 10^9) — 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} ≤ 10^9), 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} ≤ 10^9), 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
1 1000000000
1
1000000000

Output
2000000000

Input
10 1
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
1 1 1 1 1 1 1 1 1 1

Output
0

Input
3 1
2 1 4
11 3 16

Output
4

Input
4 3
4 3 5 6
11 12 14 20

Output
3

Difficulty: MEDIUM

Solutions:
def can_make(n, k, one_cake, have, cake):
	i = 0
	while i < n:
		needed = cake * one_cake[i] - have[i]
		i += 1
		if needed > k:
			return False
		elif needed > 0:
			k -= needed
	return True

def binary_search(n, k, one_cake, have):
	lo = 0
	hi = 2000000000
	while lo < hi:
		mid = int((lo + hi + 1) / 2)
		if can_make(n, k, one_cake, have, mid):
			lo = mid
		else:
			hi = mid - 1
	return lo
nk_in = list(input().split())
one_cake_in = list(input().split())
have_in = list(input().split())
nk_in = list(map(int, nk_in))
one_cake_in = list(map(int, one_cake_in))
have_in = list(map(int, have_in))
n = nk_in[0]
k = nk_in[1]
print(binary_search(n, k, one_cake_in, have_in))


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])
l = mn
r = mn + k + 1
while r > l + 1:
	m = (l + r) // 2
	cnt = k
	for i in range(n):
		if yes[i] < no[i] * m:
			cnt -= no[i] * m - yes[i]
	if cnt >= 0:
		l = m
	else:
		r = m
stdout.write(str(l))


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


(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
(n, k) = map(int, input().split())
grams = list(map(int, input().split()))
has = list(map(int, input().split()))
tmp = -1
for i in range(len(grams)):
	tmp = max(tmp, has[i] // grams[i] + k // grams[i])

def func(grams, has, mid, k):
	if mid == tmp + 1:
		return False
	for i in range(len(grams)):
		if grams[i] * mid > has[i]:
			if grams[i] * mid - has[i] - k > 0:
				return False
			else:
				k = k - (grams[i] * mid - has[i])
	return True
low = 0
high = tmp
while low <= high:
	mid = (low + high) // 2
	if func(grams, has, mid, k):
		if not func(grams, has, mid + 1, k):
			print(mid)
			break
		else:
			low = mid + 1
	else:
		high = mid - 1


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) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	lo = 0
	hi = 3 * 10 ** 9
	while lo + 1 < hi:
		mid = (lo + hi) // 2
		if can_make(a, b, k, mid):
			lo = mid
		else:
			hi = mid
	print(lo)
main()


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l1 = list(map(int, input().split()))
l2 = []
l3 = []
su = sum(l)

def chek(N):
	v = 0
	for i in range(n):
		d = max(0, N - l2[i])
		if d > 0:
			d -= 1
			v += l[i] - l3[i]
		v += l[i] * d
	if v <= m:
		return False
	else:
		return True

def search():
	p = 0
	ost = 10000000001
	while p <= ost:
		mid = (p + ost) // 2
		if chek(mid):
			ost = mid - 1
		else:
			p = mid + 1
	return p
for i in range(n):
	l3.append(l1[i] % l[i])
	l2.append(l1[i] // l[i])
e = search()
if chek(e):
	print(e - 1)
else:
	print(e)


(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)


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


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()))
beg = 0
end = 10 ** 10
while beg <= end:
	cnt = 0
	mid = (beg + end) // 2
	x = mid
	flag = 0
	for i in range(n):
		if a[i] * mid > b[i]:
			cnt += a[i] * mid - b[i]
			if cnt > k:
				flag = 1
				break
	if flag != 1:
		beg = mid + 1
	else:
		end = mid - 1
print(beg - 1)


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

def func(x):
	global n, k
	cnt = 0
	for i in range(n):
		cnt += max(0, a[i] * x - b[i])
	if cnt > k:
		return False
	return True
lb = 0
ub = 2 * 10 ** 9 + 1
while lb < ub:
	mid = (lb + ub + 1) // 2
	if func(mid):
		lb = mid
	else:
		ub = mid - 1
print(lb)


import sys

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

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))


(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, 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)


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

def f(a, b, magic, n, mid):
	y = 0
	for x in range(n):
		if a[x] * mid > b[x]:
			y += a[x] * mid - b[x]
			if y > magic:
				return False
	return True
i = 0
bx = 10 ** 18
while i < bx:
	mid = (i + bx) // 2
	if i == mid and bx == mid + 1:
		if f(a, b, ax[1], ax[0], mid):
			print(i)
			break
		else:
			print(bx)
			break
	elif f(a, b, ax[1], ax[0], mid):
		i = mid
	else:
		bx = mid


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())


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 ** 18
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)


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 = 10000000000.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))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
low = 0
high = 2 * 10000000000.0

def p(mm):
	temp = k
	result = True
	for i in range(len(b)):
		s = b[i]
		f = a[i]
		rem = s - f * mm
		if rem < 0:
			temp += rem
			if 0 > temp:
				return False
	return result
while low < high:
	m = int((low + high) / 2)
	if p(m):
		low = m + 1
	else:
		high = m
if p(low):
	print(int(low))
else:
	print(int(low - 1))


import math

def binary_search_mod(array, target):
	lower = 0
	upper = len(array)
	while lower + 1 < upper:
		x = lower + (upper - lower) // 2
		val = array[x]
		if target >= val:
			lower = x
		else:
			upper = x
	x = lower
	val = array[x]
	return (x, val)

def get_max_cakes(a, b, k):
	total = [(math.floor(b[i] / a[i]), a[i], b[i] - a[i] * math.floor(b[i] / a[i])) for i in range(len(a))]
	total = sorted(total)
	k_rest = total[0][2]
	a_cum = total[0][1]
	mn = total[0][0]
	mp = k
	for i in range(1, len(total)):
		diff = total[i][0] - total[i - 1][0]
		sx = diff * a_cum - k_rest
		if sx <= mp:
			a_cum += total[i][1]
			mp -= sx
			mn += diff
			k_rest = total[i][2]
		else:
			return mn + int((mp + k_rest) / a_cum)
	return mn + int((mp + k_rest) / a_cum)
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) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
loo = 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 False
	return True
while loo < hi:
	m = (loo + hi) // 2
	if p(m):
		loo = m + 1
	else:
		hi = m
print(int(loo if p(loo) else loo - 1))


def ok(m):
	k2 = k
	for i in range(n):
		o = a[i] * m - b[i]
		if o > 0:
			k2 -= o
	if k2 >= 0:
		return True
	return False
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = 0
r = 2000000001
m = (r + l) // 2
while r - l > 1:
	if ok(m):
		l = m
	else:
		r = m
	m = (r + l) // 2
print(l)


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)


def calculate_cookie(n, k, a, b, mid) -> bool:
	sum = 0
	for i in range(n):
		x = b[i] - a[i] * mid
		if x < 0:
			sum += x
	if k + sum >= 0:
		return True
	else:
		return False
I = lambda : map(int, input().split())
(n, k) = I()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
mid = 0
low = 0
high = pow(10, 18)
while low <= high:
	mid = (low + high) // 2
	flag = calculate_cookie(n, k, a, b, mid)
	if flag:
		if calculate_cookie(n, k, a, b, mid + 1):
			low = mid + 1
		else:
			ans = mid
			break
	else:
		high = mid - 1
print(mid)


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 = 1e+20
	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(int(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 = []
high = 0
for i in range(n):
	cookies = min(cookies, b[i] // a[i])
	high = max(high, k // a[i])
for i in range(n):
	c.append(b[i] - cookies * a[i])

def find(cook):
	cnt = 0
	for i in range(n):
		temp = max(0, cook * a[i] - c[i])
		cnt += temp
	if cnt <= k:
		return True
	return False
ans = 0
low = 0
while low <= high:
	m = (low + high) // 2
	if find(m):
		ans = max(ans, m)
		low = m + 1
	else:
		high = m - 1
print(ans + cookies)


import sys

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

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) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(binary_search(n, k, a, b))


read = lambda : list(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]

def f(x):
	k1 = k
	for i in range(n):
		if c[i] >= x:
			continue
		cnt = (x - c[i] - 1) * a[i] + r[i]
		k1 -= cnt
		if k1 < 0:
			return False
	return True
(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 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) = input().split(' ')
(n, k) = [int(n), int(k)]
list1 = list(map(int, input().split(' ')))
list2 = list(map(int, input().split(' ')))
low = 0
high = 2 * 10 ** 9
while low < high:
	if high - low % 2 != 0:
		mid = low + (high - low) // 2 + 1
	else:
		mid = low + (high - low) // 2
	d = k
	for i in range(n):
		if list1[i] * mid <= list2[i]:
			continue
		else:
			c = list1[i] * mid - list2[i]
			if d >= c:
				d = d - c
				continue
			else:
				high = mid - 1
				break
	if high != mid - 1:
		low = mid
print(low)


def check(m):
	need = 0
	for (ax, bx) in zip(a, b):
		need += max(0, ax * m - bx)
	return need <= k
(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 = (l + r) // 2
	if check(m):
		l = m
	else:
		r = m
print(l)


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)


(no_of_indegrants, no_of_gram_magic) = map(int, input().split())

def f(mid1, num):
	global no_of_indegrants
	li3 = li2[:]
	for i in range(no_of_indegrants):
		if li3[i] < li1[i] * mid:
			num = num - (li1[i] * mid - li3[i])
		if num < 0:
			return False
	return True
li1 = list(map(int, input().split()))
li2 = list(map(int, input().split()))
li3 = [0 for i in range(no_of_indegrants)]
for i in range(no_of_indegrants):
	li3[i] = li2[i] // li1[i]
num = min(li3)
for i in range(no_of_indegrants):
	li2[i] = li2[i] - num * li1[i]
l = 0
h = no_of_gram_magic + 1
while h - l > 1:
	num1 = no_of_gram_magic
	mid = (l + h) // 2
	if f(mid, num1):
		l = mid
	else:
		h = mid
print(num + l)


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

def bin_sear(l, h):
	while h - l > 1:
		mi = (h + l) // 2
		s = sum((max(a[i] * mi - b[i], 0) for i in range(n)))
		if s <= m:
			l = mi
		else:
			h = mi
	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)


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)


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


(n, k) = map(int, input().split())
required = list(map(int, input().split()))
has = list(map(int, input().split()))
low = 0
high = 10 ** 10 + 10
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:
			break
	else:
		high = mid - 1
		if low > high:
			break
print(high)


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)


(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()]
(x, y) = (0, max(B) + k + 1)
z = (x + y) // 2
while z != x:
	credit = 0
	for i in range(n):
		credit += max(z * A[i] - B[i], 0)
	if credit > k:
		y = z
	else:
		x = z
	z = (x + y) // 2
print(z)


(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)


(n, k) = map(int, input().split())
recipe = list(map(int, input().split()))
current = list(map(int, input().split()))
high = max(current) + 1 + k
low = 0

def canMake(x):
	magic_needed = 0
	for i in range(n):
		diff = current[i] - recipe[i] * x
		if diff < 0:
			magic_needed -= diff
	return magic_needed <= k
while True:
	curr = (high + low) // 2
	result = canMake(curr)
	if result and (not canMake(curr + 1)):
		break
	if result:
		low = curr
	else:
		high = curr
print(curr)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
st = 0
end = 10 ** 10
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)


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)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = 0
r = int(10000000000.0)
while r - l > 1:
	mid = (r + l) // 2
	fail = False
	kk = k
	for i in range(n):
		if b[i] < a[i] * mid:
			if kk > 0:
				kk -= a[i] * mid - b[i]
				if kk < 0:
					fail = True
			else:
				fail = True
	if fail:
		r = mid
	else:
		l = mid
print(l)


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)


from collections import Counter, OrderedDict
from itertools import permutations as perm
from fractions import Fraction
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(n, k) = gil()
(a, b) = (gil(), gil())
have = sum(b)
demand = sum(a)

def isPos(x):
	diff = k
	for i in range(n):
		diff += min(0, b[i] - a[i] * x)
	return diff >= 0
(l, r) = (0, int(2000000000.0))
ans = 0
while l <= r:
	mid = l + r >> 1
	if isPos(mid):
		ans = mid
		l = mid + 1
	else:
		r = mid - 1
print(ans)


(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)


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 = list(map(int, input().split()))
b = list(map(int, input().split()))

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
l = 0
u = 2 * 1000000000.0 + 1
while l + 1 < u:
	m = (l + u) // 2
	if f(k, m):
		l = m
	else:
		u = m
print(int(l))


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)


import math
(n, k) = map(int, input().split())
cost = list(map(int, input().split()))
stock = list(map(int, input().split()))
lo = 0
hi = 4000000000
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)


(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))


(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 = 100000000000000000
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)


(n, m) = [int(x) for x in input().split()]
need = [int(x) for x in input().split()]
has = [int(x) for x in input().split()]
lo = 0
hi = 10 ** 12
while lo <= hi:
	mid = int(int(lo + hi) / int(2))
	magic = 0
	for x in range(len(need)):
		ineed = mid * need[x]
		if ineed > has[x]:
			magic = magic + (ineed - has[x])
	if magic > m:
		hi = mid - 1
	else:
		lo = mid + 1
print(int(int(lo + hi) / int(2)))


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
(l, r) = (0, 10 ** 10)
ans = 0
found = False

def possible(k, c):
	req = 0
	for i in range(n):
		if b[i] < a[i] * c:
			req += a[i] * c - b[i]
	return req <= k
while l < r:
	mid = (l + r) // 2
	if l + 1 == r:
		if possible(k, l):
			found = True
			ans = l
		if possible(k, r):
			found = True
			ans = l
		break
	if possible(k, mid):
		found = True
		ans = mid
		l = mid
	else:
		r = mid
if found:
	print(ans)
else:
	print(0)


import sys
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

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

def si():
	return input()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def read():
	tc = 0
	if tc:
		input = sys.stdin.readline
	else:
		sys.stdin = open('input1.txt', 'r')
		sys.stdout = open('output1.txt', 'w')

def solve():
	(n, k) = mi()
	a = li()
	b = li()
	x = 0
	for i in range(n):
		x = max(x, ceil(b[i] / a[i]))
	l = 0
	r = x
	ans = 0
	while l <= r:
		m = l + (r - l) // 2
		s = 0
		for i in range(n):
			if a[i] * m > b[i]:
				s += a[i] * m - b[i]
		if s > k:
			r = m - 1
		else:
			ans = m
			l = m + 1
	s1 = sum(a)
	if k > s:
		k -= s
		ans += k // s1
	print(ans)
solve()


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 = 2000000000
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 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
	return False
p = input()
p = p.split()
n = int(p[0])
k = int(p[1])
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
left = 0
right = 2 * 10 ** 9 + 1
while left < right - 1:
	mid = (left + right) // 2
	if f(mid):
		right = mid
	else:
		left = mid
print(left)


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

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():
	nk = list(map(int, input().split(' ')))
	(n, k) = (nk[0], nk[1])
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	print(bin_src(a, b, n, k, 0, 2 * 10 ** 9 + 1))
main()


import sys, math, random
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
(n, k) = invr()
a = inara()
b = inara()
hi = 10000000000000000
lo = 0
ans = 0

def possible(cake):
	lagbe = 0
	for i in range(n):
		temp = a[i] * cake
		if temp > b[i]:
			lagbe += temp - b[i]
			if lagbe > k:
				break
	return lagbe <= k
while hi >= lo:
	mid = (hi + lo) // 2
	if possible(mid):
		ans = max(ans, mid)
		lo = mid + 1
	else:
		hi = mid - 1
print(ans)


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

def check(x):
	global n, k, A, b
	yn = 0
	a = k
	for i in range(n):
		if A[i] * x > B[i]:
			yn += A[i] * x - B[i]
			k -= A[i] * x - B[i]
		if k < 0:
			k = a
			return False
	k = a
	return k >= yn

def main():
	l = -1
	mini = 10 ** 10
	for i in range(n):
		if (B[i] + k) / A[i] < mini:
			mini = (B[i] + k) / A[i]
	mini += 1
	r = mini
	r = int(r)
	while r - l > 1:
		m = l + (r - l) // 2
		if check(m):
			l = m
		else:
			r = m
	print(l)
main()


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))


def ok(u, a, b, n, k):
	for i in range(n):
		if b[i] >= a[i] * u:
			continue
		else:
			k -= a[i] * u - b[i]
			if k < 0:
				return False
	return k >= 0
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(l, r) = (0, 2000000010)
while l < r - 1:
	g = (l + r) // 2
	if ok(g, a, b, n, k):
		l = g
	else:
		r = g
print(l)


def ok(x):
	need = 0
	for i in range(n):
		tmp = a[i] * x - b[i]
		if tmp > 0:
			need += tmp
	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)