Consider a system of n water taps all pouring water into the same container. The i-th water tap can be set to deliver any amount of water from 0 to a_{i} ml per second (this amount may be a real number). The water delivered by i-th tap has temperature t_{i}.

If for every $i \in [ 1, n ]$ you set i-th tap to deliver exactly x_{i} ml of water per second, then the resulting temperature of water will be $\frac{\sum_{i = 1}^{n} x_{i} t_{i}}{\sum_{i = 1}^{n} x_{i}}$ (if $\sum_{i = 1}^{n} x_{i} = 0$, then to avoid division by zero we state that the resulting water temperature is 0).

You have to set all the water taps in such a way that the resulting temperature is exactly T. What is the maximum amount of water you may get per second if its temperature has to be T?


-----Input-----

The first line contains two integers n and T (1 ≤ n ≤ 200000, 1 ≤ T ≤ 10^6) — the number of water taps and the desired temperature of water, respectively.

The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^6) where a_{i} is the maximum amount of water i-th tap can deliver per second.

The third line contains n integers t_1, t_2, ..., t_{n} (1 ≤ t_{i} ≤ 10^6) — the temperature of water each tap delivers.


-----Output-----

Print the maximum possible amount of water with temperature exactly T you can get per second (if it is impossible to obtain water with such temperature, then the answer is considered to be 0).

Your answer is considered correct if its absolute or relative error doesn't exceed 10^{ - 6}.


-----Examples-----
Input
2 100
3 10
50 150

Output
6.000000000000000

Input
3 9
5 5 30
6 6 10

Output
40.000000000000000

Input
2 12
1 3
10 15

Output
1.666666666666667

Source: codeforces | Difficulty: HARD
Tags: Sorting

Greedy algorithms


Solutions:
def get_max_volume(sources, required_temperature):
	max_volume = 0.0
	temp = 0
	higher_sources = []
	lower_sources = []
	for (volume, temperature) in sources:
		delta_temp = temperature - required_temperature
		if delta_temp > 0:
			higher_sources.append((volume, delta_temp))
		elif delta_temp < 0:
			lower_sources.append((volume, delta_temp))
		max_volume += volume
		temp += volume * delta_temp
	higher_sources.sort(key=lambda v: v[1])
	lower_sources.sort(key=lambda v: -v[1])
	while abs(temp / max_volume) >= 1e-06 and (len(lower_sources) > 0 or temp >= 0) and (len(higher_sources) > 0 or temp <= 0):
		if temp < 0:
			(volume, delta_temp) = lower_sources.pop()
			if temp - delta_temp * volume >= 0:
				required_volume = temp / delta_temp
				return max_volume - required_volume
			temp -= delta_temp * volume
			max_volume -= volume
		else:
			(volume, delta_temp) = higher_sources.pop()
			if temp - delta_temp * volume <= 0:
				required_volume = temp / delta_temp
				return max_volume - required_volume
			temp -= delta_temp * volume
			max_volume -= volume
	if abs(temp / max_volume) < 1e-06:
		return max_volume
	return 0.0
(n, t) = list(map(int, input().split()))
vs = input().split()
ts = input().split()
ss = [(int(vs[i]), int(ts[i])) for i in range(n)]
print(get_max_volume(ss, t))


(n, nt) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
c = 0
ans = 0
l = []
r = []
for i in range(n):
	if t[i] < nt:
		l.append([nt - t[i], a[i]])
	if t[i] > nt:
		r.append([t[i] - nt, a[i]])
	if t[i] == nt:
		ans += a[i]
l = sorted(l, key=lambda x: x[0])
r = sorted(r, key=lambda x: x[0])
il = 0
ir = 0
lv = 0.0
rv = 0.0
lvv = 0.0
rvv = 0.0
while 1:
	if lv <= rv:
		if il == len(l):
			break
		lv += l[il][0] * l[il][1]
		lvv += l[il][1]
		il += 1
	else:
		if ir == len(r):
			break
		rv += r[ir][0] * r[ir][1]
		rvv += r[ir][1]
		ir += 1
if rv < lv:
	lv -= l[il - 1][0] * l[il - 1][1]
	lvv -= l[il - 1][1]
	lvv += (rv - lv) / l[il - 1][0]
elif lv < rv:
	rv -= r[ir - 1][0] * r[ir - 1][1]
	rvv -= r[ir - 1][1]
	rvv += (lv - rv) / r[ir - 1][0]
ans += rvv
ans += lvv
print('%.8f' % ans)


rd = lambda : map(int, input().split())
(n, t) = rd()
a = list(rd())
b = list(rd())
x = [[b[i], a[i]] for i in range(n)]
x.sort()
(tot, val) = (sum(a), 0)
for i in range(n):
	val += (t - x[i][0]) * x[i][1]
if val < 0:
	for i in range(n - 1, -1, -1):
		if val - x[i][1] * (t - x[i][0]) >= 0:
			tot -= val / (t - x[i][0])
			val = 0
			break
		tot -= x[i][1]
		val -= (t - x[i][0]) * x[i][1]
if val > 0:
	for i in range(n):
		if val - x[i][1] * (t - x[i][0]) <= 0:
			tot -= val / (t - x[i][0])
			val = 0
			break
		tot -= x[i][1]
		val -= (t - x[i][0]) * x[i][1]
print('%.12f' % tot)


import sys
input = sys.stdin.readline
(n, T) = map(int, input().split())
a = list(map(int, input().split()))
t = list(map(int, input().split()))
for i in range(n):
	t[i] -= T
lower = []
upper = []
max_lower = 0
max_upper = 0
ans = 0
for i in range(n):
	if t[i] == 0:
		ans += a[i]
	elif t[i] < 0:
		lower.append((-t[i], a[i]))
		max_lower += abs(a[i] * t[i])
	else:
		upper.append((t[i], a[i]))
		max_upper += abs(a[i] * t[i])
max_heat = min(max_upper, max_lower)
lower.sort()
upper.sort()
tmp = 0
for (ti, ai) in lower:
	if tmp + ti * ai < max_heat:
		ans += ai
		tmp += ti * ai
	else:
		ans += (max_heat - tmp) / ti
		tmp = max_heat
tmp = 0
for (ti, ai) in upper:
	if tmp + ti * ai < max_heat:
		ans += ai
		tmp += ti * ai
	else:
		ans += (max_heat - tmp) / ti
		tmp = max_heat
print(ans)


def f(t, x):
	for i in range(1, len(t) + 1):
		ps[i] = ps[i - 1] + t[i - 1][0] * t[i - 1][1]
	l = 0
	r = len(t) + 1
	while l < r:
		s = (l + r) // 2
		if ps[s] <= x:
			l = s + 1
		else:
			r = s
	return l - 1
(n, T) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
t = [(int(x) - T, a[i]) for (i, x) in enumerate(input().split())]
tp = list(sorted([e for e in t if e[0] > 0]))
tm = list(sorted([(-x[0], x[1]) for x in [e for e in t if e[0] < 0]]))
ep = sum((e[0] * e[1] for e in tp))
em = sum((e[0] * e[1] for e in tm))
ps = [0] * (n + 1)
res = sum([e[1] for e in [e for e in t if e[0] == 0]])
if ep > 0 and em > 0:
	if ep < em:
		it = f(tm, ep)
		res += sum([e[1] for e in tp])
		res += sum([e[1] for e in tm[:it]])
		if it < len(tm):
			res += (ep - ps[it]) / tm[it][0]
	else:
		it = f(tp, em)
		res += sum([e[1] for e in tm])
		res += sum([e[1] for e in tp[:it]])
		if it < len(tp):
			res += (em - ps[it]) / tp[it][0]
print(res)


import sys
[n, T] = list(map(int, sys.stdin.readline().strip().split()))
ais = list(map(int, sys.stdin.readline().strip().split()))
tis = list(map(int, sys.stdin.readline().strip().split()))
i_0 = [i for i in range(n) if tis[i] == T]
i_hot = [i for i in range(n) if tis[i] > T]
i_cold = [i for i in range(n) if tis[i] < T]
tis = [abs(ti - T) for ti in tis]
w_hot = sum((ais[i] * tis[i] for i in i_hot))
w_cold = sum((ais[i] * tis[i] for i in i_cold))
if w_hot > w_cold:
	(w_hot, w_cold) = (w_cold, w_hot)
	(i_hot, i_cold) = (i_cold, i_hot)
x_max = sum((ais[i] for i in i_0)) + sum((ais[i] for i in i_hot))
w = w_hot
i_cold.sort(key=lambda _k: tis[_k])
for i in i_cold:
	(a, t) = (ais[i], tis[i])
	if a * t <= w:
		w -= a * t
		x_max += a
	else:
		x_max = x_max + float(w) / t
		w = 0
		break
print(float(x_max))


eps = 1e-09
(n, T) = map(int, input().split())
a = [*map(int, input().split())]
t = [*map(int, input().split())]
l = sorted(zip(t, a))
S = sum((x * y for (x, y) in l))
V = sum(a)
while l and S - V * T > V * eps and (l[-1][0] > T):
	(x, y) = l.pop()
	d = min(y, (S - V * T) / (x - T))
	S -= x * d
	V -= d
l.reverse()
while l and V * T - S > V * eps and (l[-1][0] < T):
	(x, y) = l.pop()
	d = min(y, (V * T - S) / (T - x))
	S -= x * d
	V -= d
print(round(V, 7) if abs(S - V * T) <= V * eps else 0)


(n, T) = list(map(int, input().split(' ')))
r = list()
r.append(list(map(int, input().split(' '))))
r.append(list(map(int, input().split(' '))))
r.append(list())
for i in range(len(r[0])):
	r[2].append((r[0][i], r[1][i]))
r[2].sort(key=lambda x: x[::-1])
for i in range(n):
	r[0][i] = r[2][i][0]
	r[1][i] = r[2][i][1]
fl = True
tau = sum(r[0]) * T > sum(map(lambda x: x[0] * x[1], r[2]))
if tau:
	r[2].reverse()
	fl = False
tau1 = not tau
summ = list()
proi = list()
su = 0
pr = 0
for i in range(n):
	su += r[2][i][0]
	summ.append(su)
	pr += r[2][i][0] * r[2][i][1]
	proi.append(pr)
lev = 0
pra = n - 1
while lev < n - 1 and (r[2][lev][1] <= T and fl or (r[2][lev][1] >= T and (not fl))):
	lev += 1
test = lev
while lev != pra:
	tau = tau1
	tau1 = summ[(lev + pra) // 2 - 1] * T > proi[(lev + pra) // 2 - 1]
	if tau == tau1:
		lev = (lev + pra) // 2 + 1
	else:
		pra = (lev + pra) // 2
		tau1 = not tau1
tau = summ[-1] * T > proi[-1]
tau1 = summ[max(pra - 1, 0)] * T > proi[max(pra - 1, 0)]
if tau != tau1:
	x = (summ[max(pra - 1, 0)] * T - proi[max(pra - 1, 0)]) / (r[2][pra][1] - T)
	x = summ[max(pra - 1, 0)] + x
	print(x)
else:
	tau = tau1
	tau1 = summ[max(lev - 2, 0)] * T > proi[max(lev - 2, 0)]
	if tau != tau1:
		x = (summ[max(lev - 2, 0)] * T - proi[max(lev - 2, 0)]) / (r[2][max(lev - 1, 0)][1] - T)
		x = summ[max(lev - 2, 0)] + x
		print(x)
	else:
		x = 0
		if test == 0 or test == 1:
			if r[2][0][1] == T:
				x = r[2][0][0]
		else:
			if r[2][test][1] != T:
				test -= 1
			x = summ[test]
			while test > -1 and r[2][test][1] == T:
				test -= 1
			if test != -1:
				x -= summ[test]
		print(x)


(n, T) = map(int, input().split())
v = list(map(int, input().split()))
t = list(map(int, input().split()))
(plus, minus) = ([], [])
(pr, ans) = (0, 0)
for i in range(n):
	if t[i] < T:
		minus.append([T - t[i], i])
	elif t[i] > T:
		plus.append([t[i] - T, i])
	else:
		ans += v[i]
(max1, max2) = (0, 0)
for i in range(len(minus)):
	max1 += minus[i][0] * v[minus[i][1]]
for i in range(len(plus)):
	max2 += plus[i][0] * v[plus[i][1]]
if max1 > max2:
	minus.sort()
	i = 0
	while pr != max2:
		if max2 - pr < v[minus[i][1]] * minus[i][0]:
			ans += (max2 - pr) / minus[i][0]
			pr += max2 - pr
		else:
			ans += v[minus[i][1]]
			pr += v[minus[i][1]] * minus[i][0]
		i += 1
	for i in range(len(plus)):
		ans += v[plus[i][1]]
else:
	plus.sort()
	i = 0
	while pr != max1:
		if max1 - pr < v[plus[i][1]] * plus[i][0]:
			ans += (max1 - pr) / plus[i][0]
			pr += max1 - pr
		else:
			ans += v[plus[i][1]]
			pr += v[plus[i][1]] * plus[i][0]
		i += 1
	for i in range(len(minus)):
		ans += v[minus[i][1]]
print(ans)


import sys
from operator import lt, gt, le, ge, itemgetter
(n, t) = map(int, input().split())
a = list(zip(list(map(int, input().split())), list(map(int, input().split()))))
nume = sum((a[i][0] * a[i][1] for i in range(n)))
deno = sum((a[i][0] for i in range(n)))
if nume / deno > t:
	(op1, op2, rev) = (gt, le, False)
else:
	(op1, op2, rev) = (lt, ge, True)
a.sort(key=itemgetter(1), reverse=rev)
while len(a) > 1 and op1((nume - a[-1][0] * a[-1][1]) / (deno - a[-1][0]), t):
	nume -= a[-1][0] * a[-1][1]
	deno -= a[-1][0]
	a.pop()
nume -= a[-1][0] * a[-1][1]
deno -= a[-1][0]
(ok, ng) = (0.0, float(a[-1][0]))
for _ in range(50):
	mid = (ok + ng) / 2
	if op2((nume + mid * a[-1][1]) / (deno + mid), t):
		ok = mid
	else:
		ng = mid
print(deno + ok)


(n, t) = map(int, input().strip().split(' '))
x = list(map(int, input().strip().split(' ')))
temp = list(map(int, input().strip().split(' ')))
for i in range(n):
	temp[i] -= t
pos = []
neg = []
ans = 0
negsum = 0
possum = 0
for i in range(n):
	if temp[i] < 0:
		negsum += temp[i] * x[i]
		neg.append([temp[i] * -1, x[i]])
	elif temp[i] > 0:
		possum += temp[i] * x[i]
		pos.append([temp[i], x[i]])
	else:
		ans += x[i]
if abs(negsum) > possum:
	for i in pos:
		ans += i[1]
	neg.sort()
	for i in neg:
		t = i[0] * i[1] * -1
		if t + possum < 0:
			ans += possum * 1.0 / i[0]
			break
		else:
			ans += i[1]
			possum += t
	print(ans)
elif possum > abs(negsum):
	for i in neg:
		ans += i[1]
	pos.sort()
	for i in pos:
		t = i[0] * i[1]
		if t + negsum > 0:
			ans += abs(negsum * 1.0 / i[0])
			break
		else:
			ans += i[1]
			negsum += t
	print(ans)
else:
	print(sum(x))


rd = lambda : list(map(int, input().split()))
(n, t) = rd()
(a, b) = (rd(), rd())
x = [[t - b[i], a[i]] for i in range(n)]
x.sort()
(c, v) = (sum(a), sum((i * j for (i, j) in x)))
if v:
	f = 2 * (v < 0) - 1
	for i in range(n)[::f]:
		if f * (v - x[i][1] * x[i][0]) >= 0:
			c -= v / x[i][0]
			break
		c -= x[i][1]
		v -= x[i][0] * x[i][1]
print(c)


(n, T) = map(int, input().split())
a = list(map(int, input().split()))
x = list(map(int, input().split()))
m = []
q = 0
for i in range(n):
	m += [[x[i], a[i]]]
	q += a[i] * x[i]
asu = sum(a)
try:
	if q / asu == T:
		print(asu)
	elif q / asu > T:
		m.sort()
		asu -= m[-1][1]
		q -= m[-1][0] * m[-1][1]
		while q / asu > T:
			m.pop()
			asu -= m[-1][1]
			q -= m[-1][0] * m[-1][1]
		print(asu + m[-1][1] * ((T * asu - q) / (m[-1][1] * m[-1][0] - T * m[-1][1])))
	else:
		m.sort(reverse=True)
		asu -= m[-1][1]
		q -= m[-1][0] * m[-1][1]
		while q / asu < T:
			m.pop()
			asu -= m[-1][1]
			q -= m[-1][0] * m[-1][1]
		print(asu + m[-1][1] * ((T * asu - q) / (m[-1][1] * m[-1][0] - T * m[-1][1])))
except ZeroDivisionError:
	print(0)


(n, T) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
(tp, tm) = ([], [])
s = 0
for (i, x) in enumerate(input().split()):
	dt = int(x) - T
	if dt > 0:
		tp.append([dt, a[i]])
	elif dt < 0:
		tm.append([-dt, a[i]])
	else:
		s += a[i]
tp.sort()
tm.sort()
(i, j) = (0, 0)
while i < len(tp) and j < len(tm):
	qp = tp[i][0] * tp[i][1]
	qm = tm[j][0] * tm[j][1]
	if qp > qm:
		r = tm[j][0] / tp[i][0]
		s += (1 + r) * tm[j][1]
		tp[i][1] -= tm[j][1] * r
		j += 1
	else:
		r = tp[i][0] / tm[j][0]
		s += (1 + r) * tp[i][1]
		tm[j][1] -= tp[i][1] * r
		i += 1
print(s)


import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
	(n, T) = nm()
	a = nl()
	t = nl()
	if min(t) > T or max(t) < T:
		print(0)
		return
	g = [(t[i] - T, i) for i in range(n)]
	h = sum(((t[i] - T) * a[i] for i in range(n)))
	ans = sum(a)
	if h < 0:
		g.sort()
		for (x, i) in g:
			if h < x * a[i]:
				ans -= a[i]
				h -= x * a[i]
			else:
				if h and x != 0:
					ans -= h / x
				break
	elif h > 0:
		g.sort(reverse=True)
		for (x, i) in g:
			if h > x * a[i]:
				ans -= a[i]
				h -= x * a[i]
			else:
				if h and x != 0:
					ans -= h / x
				break
	print(ans)
	return
solve()


(n, t) = list(map(int, input().split()))
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l = [[l2[i], l1[i]] for i in range(n)]
l.sort()
s1 = sum([l[i][0] * l[i][1] for i in range(n)])
s2 = sum(l1)
s = s1 / s2
f = n - 1
d = 0
if s < t:
	while s < t and d < n:
		s2 = s2 - l[d][1]
		s1 = s1 - l[d][0] * l[d][1]
		if s2 != 0:
			s = s1 / s2
		if s > t:
			s2 += (s2 * t - s1) / (l[d][0] - t)
			break
		elif s == t:
			break
		else:
			d += 1
elif s > t:
	while s > t and f >= 0:
		s2 = s2 - l[f][1]
		s1 = s1 - l[f][0] * l[f][1]
		if s2 != 0:
			s = s1 / s2
		if s < t:
			s2 += (t * s2 - s1) / (l[f][0] - t)
			break
		elif s == t:
			break
		else:
			f -= 1
print(s2)


R = lambda : map(int, input().split())
(n, temp) = R()
a = list(R())
t = list(R())
v = sorted([(t[i] - temp, a[i]) for i in range(n)])
r = sum([v[i][1] for i in range(n) if v[i][0] == 0])
pos = sum([v[i][0] * v[i][1] for i in range(n) if v[i][0] > 0])
neg = sum([abs(v[i][0]) * v[i][1] for i in range(n) if v[i][0] < 0])
pa = sum([v[i][1] for i in range(n) if v[i][0] > 0])
na = sum([v[i][1] for i in range(n) if v[i][0] < 0])
if pos == 0 or neg == 0:
	print(r)
	return
for i in range(n):
	if v[i][0] >= 0:
		stn = i - 1
		break
for i in range(n):
	if v[i][0] > 0:
		stp = i
		break
if neg < pos:
	r += na
	rem = neg * 1.0
	for i in range(stp, n):
		if v[i][0] * v[i][1] >= rem:
			r += rem / v[i][0]
			rem = 0
		else:
			r += v[i][1]
			rem -= v[i][0] * v[i][1]
else:
	r += pa
	rem = pos * 1.0
	for i in reversed(range(stn + 1)):
		if abs(v[i][0]) * v[i][1] >= rem:
			r += rem / abs(v[i][0])
			rem = 0
		else:
			r += v[i][1]
			rem -= abs(v[i][0]) * v[i][1]
print(r)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
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')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=300006, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.height = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val == 0:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
			elif val >= 1:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left

	def do(self, temp):
		if not temp:
			return 0
		ter = temp
		temp.height = self.do(ter.left) + self.do(ter.right)
		if temp.height == 0:
			temp.height += 1
		return temp.height

	def query(self, xor):
		self.temp = self.root
		cur = 0
		i = 31
		while i > -1:
			val = xor & 1 << i
			if not self.temp:
				return cur
			if val >= 1:
				self.opp = self.temp.right
				if self.temp.left:
					self.temp = self.temp.left
				else:
					return cur
			else:
				self.opp = self.temp.left
				if self.temp.right:
					self.temp = self.temp.right
				else:
					return cur
			if self.temp.height == pow(2, i):
				cur += 1 << i
				self.temp = self.opp
			i -= 1
		return cur
(n, T) = map(int, input().split())
high = []
low = []
ans = 0
l = 0
w = 0
w1 = 0
qw = 0
qw1 = 0
q = list(map(int, input().split()))
qe = list(map(int, input().split()))
for i in range(n):
	(b, a) = (q[i], qe[i])
	if a < T:
		low.append((T - a, b))
		w += b
		qw += (T - a) * b
		l += (T - a) * b
	elif a > T:
		w1 += b
		high.append((a - T, b))
		qw1 += (a - T) * b
		l -= (a - T) * b
	else:
		ans += b
low.sort()
high.sort()
if len(low) == 0 or len(high) == 0:
	print(ans)
	sys.exit(0)
if l < 0:
	ans += w
	for i in range(len(high)):
		(a, b) = high[i]
		if a * b >= qw:
			ans += qw / a
			qw = 0
			break
		else:
			ans += b
			qw -= a * b
else:
	ans += w1
	for i in range(len(low)):
		(a, b) = low[i]
		if a * b >= qw1:
			ans += qw1 / a
			qw1 = 0
			break
		else:
			ans += b
			qw1 -= a * b
print(ans)


import sys
import math
EPS = 1e-09
files = True
debug = False

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

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

def range_sum(a, b):
	ass = (b - a + 1) // 2 * (a + b)
	if (a - b) % 2 == 0:
		ass += (b - a + 2) // 2
	return ass

def comba(n, x):
	return math.factorial(n) // math.factorial(n - x) // math.factorial(x)

def eq(a, b):
	return abs(a - b) <= EPS
(n, ta) = ria()
vs = ria()
ts = ria()
ks = []
up = 0
down = sum(vs)
for i in range(n):
	ks.append((ts[i], vs[i]))
	up += ts[i] * vs[i]
ks.sort()
if up / down > ta:
	if min(ts) > ta:
		print('0')
		exit(0)
	ks = list(reversed(ks))
	for (t, v) in ks:
		if down == 0:
			print(0)
			exit(0)
		if eq(up / down, ta):
			print(down)
			exit(0)
		if (up - t * v) / (down - v) > ta or eq((up - t * v) / (down - v), ta):
			up -= t * v
			down -= v
			continue
		(l, r) = (0, v)
		up -= t * v
		down -= v
		while r - l > EPS:
			m = (l + r) / 2
			if (up + t * m) / (down + m) > ta:
				r = m
			else:
				l = m
		print(down + l)
		exit(0)
else:
	if max(ts) < ta:
		print('0')
		exit(0)
	for (t, v) in ks:
		if down == 0:
			print(0)
			exit(0)
		if eq(up / down, ta):
			print(down)
			exit(0)
		if (up - t * v) / (down - v) < ta or eq((up - t * v) / (down - v), ta):
			up -= t * v
			down -= v
			continue
		(l, r) = (0, v)
		up -= t * v
		down -= v
		while r - l > EPS:
			m = (l + r) / 2
			if (up + t * m) / (down + m) < ta:
				r = m
			else:
				l = m
		print(down + l)
		exit(0)