An atom of element X can exist in n distinct states with energies E_1 < E_2 < ... < E_{n}. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. 

Three distinct states i, j and k are selected, where i < j < k. After that the following process happens:   initially the atom is in the state i, we spend E_{k} - E_{i} energy to put the atom in the state k, the atom emits a photon with useful energy E_{k} - E_{j} and changes its state to the state j, the atom spontaneously changes its state to the state i, losing energy E_{j} - E_{i}, the process repeats from step 1. 

Let's define the energy conversion efficiency as $\eta = \frac{E_{k} - E_{j}}{E_{k} - E_{i}}$, i. e. the ration between the useful energy of the photon and spent energy.

Due to some limitations, Arkady can only choose such three states that E_{k} - E_{i} ≤ U.

Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.


-----Input-----

The first line contains two integers n and U (3 ≤ n ≤ 10^5, 1 ≤ U ≤ 10^9) — the number of states and the maximum possible difference between E_{k} and E_{i}.

The second line contains a sequence of integers E_1, E_2, ..., E_{n} (1 ≤ E_1 < E_2... < E_{n} ≤ 10^9). It is guaranteed that all E_{i} are given in increasing order.


-----Output-----

If it is not possible to choose three states that satisfy all constraints, print -1.

Otherwise, print one real number η — the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10^{ - 9}.

Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $\frac{|a - b|}{\operatorname{max}(1,|b|)} \leq 10^{-9}$.


-----Examples-----
Input
4 4
1 3 5 7

Output
0.5

Input
10 8
10 13 15 16 17 19 20 22 24 25

Output
0.875

Input
3 1
2 5 10

Output
-1



-----Note-----

In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to $\eta = \frac{5 - 3}{5 - 1} = 0.5$.

In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to $\eta = \frac{24 - 17}{24 - 16} = 0.875$.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Sorting

Amortized analysis

Greedy algorithms


Solutions:
def sss(l, r, tt):
	f = -1
	while l <= r:
		mid = l + r >> 1
		if a[mid] - a[tt] <= m:
			f = mid
			l = mid + 1
		else:
			r = mid - 1
	return f
(n, m) = map(int, input().split())
a = [int(x) for x in input().split()]
f = 0
l = len(a)
Maxx = -1
for i in range(0, l - 2):
	if a[i + 2] - a[i] <= m:
		k = sss(i + 2, l - 1, i)
		if k != -1:
			Maxx = max(Maxx, (a[k] - a[i + 1]) / (a[k] - a[i]))
if Maxx == -1:
	print(-1)
else:
	print('%.15f\n' % Maxx)


(n, u) = map(int, input().split())
arr = list(map(int, input().split()))
(j, i) = (1, 0)
maxi = -1
flag = 0
for i in range(n - 1):
	if arr[i + 1] - arr[i] <= u:
		flag = 1
if flag == 0:
	print('-1')
	exit()
i = 0
while i < n - 2:
	while 1:
		if j >= n:
			j = n - 1
			break
		if arr[j] - arr[i] > u:
			j -= 1
			break
		j += 1
	if i == j:
		j += 1
	elif arr[j] == arr[i]:
		pass
	elif arr[j] - arr[i] <= u:
		maxi = max(maxi, (arr[j] - arr[i + 1]) / (arr[j] - arr[i]))
	i += 1
if maxi == 0:
	print('-1')
else:
	print(maxi)


import sys

def run():
	inp = sys.stdin.readlines()
	(n, u) = (int(x) for x in inp[0].strip().split())
	data = [int(x) for x in inp[1].strip().split()]
	ans = None
	for i in range(n - 2):
		first = data[i]
		second = data[i + 1]
		trgt = u + first
		if data[i + 2] > trgt:
			continue
		lft = i + 2
		rgt = n - 1
		while lft != rgt:
			m = (lft + rgt) // 2 + (lft + rgt) % 2
			curr = data[m]
			if curr <= trgt:
				lft = m
			else:
				rgt = m - 1
		third = data[lft]
		a = (third - second) / (third - first)
		if ans is None:
			ans = a
		else:
			ans = max(ans, a)
	if ans is None:
		ans = -1
	print(ans)
run()


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
(n, U) = ilele()
A = alele()
Ans = -1
for i in range(n - 2):
	x = A[i]
	y = x + U
	z = bisect.bisect_left(A, y, lo=i + 2, hi=n)
	if z == n:
		z -= 1
	if A[z] <= x + U:
		a = A[z]
	elif A[z - 1] <= x + U and z - 1 != i + 1:
		a = A[z - 1]
	else:
		continue
	b = (a - A[i + 1]) / (a - A[i])
	Ans = max(Ans, b)
print(Ans)


(n, u) = map(int, input().split())
v = list(map(int, input().split()))
kpd = -1
k = 0
for i in range(n):
	j = i + 1
	while k + 1 < n and v[k + 1] - v[i] <= u:
		k += 1
	if i < j and j < k:
		kpd = max(kpd, (v[k] - v[j]) / (v[k] - v[i]))
print(kpd)


(n, v) = list(map(int, input().split()))
l = list(map(int, input().split()))
ans = [-1]
for i in range(n - 2):
	uk1 = i + 2
	uk2 = n - 1
	while uk2 - uk1 > 1:
		if l[(uk2 + uk1) // 2] - l[i] <= v:
			uk1 = (uk2 + uk1) // 2
		else:
			uk2 = (uk2 + uk1) // 2
	if l[uk2] - l[i] <= v:
		ans.append((l[uk2] - l[i + 1]) / (l[uk2] - l[i]))
	elif l[uk1] - l[i] <= v:
		ans.append((l[uk1] - l[i + 1]) / (l[uk1] - l[i]))
print(max(ans))


pairs = [int(s) for s in input().split(' ')]
n = int(pairs[0])
U = int(pairs[1])
levels = [int(s) for s in input().split(' ')]
levels.sort()

def find_nearest(levels, start, finish, max_level):
	if start > finish:
		return -1
	if start > n - 1:
		return -1
	if levels[start] > max_level:
		return -1
	if levels[finish] <= max_level:
		return finish
	if finish - start < 2:
		return start
	mid = (start + finish) // 2
	if levels[mid] > max_level:
		return find_nearest(levels, start, mid, max_level)
	else:
		return find_nearest(levels, mid, finish, max_level)
coeff = -1
for j in range(1, n):
	i = j - 1
	if coeff > 1 - (levels[j] - levels[i]) / (levels[n - 1] - levels[i]):
		continue
	k = find_nearest(levels, j + 1, n - 1, U + levels[i])
	if k == -1:
		continue
	coeff = max(coeff, 1 - (levels[j] - levels[i]) / (levels[k] - levels[i]))
print(coeff)


import sys
string = sys.stdin.readline()
n = int(string.split()[0])
u = int(string.split()[1])
levels = tuple(map(int, sys.stdin.readline().split()))
if len(levels) < 3:
	sys.stdout.write('-1')
	exit(0)
(i, j, k) = (0, 1, 2)
indices = (0, 1, 2)
level_i = levels[0]
level_j = levels[1]
nu = levels[2] - level_i
nu = -1
while i < n - 2:
	while k < n - 1 and levels[k + 1] - level_i <= u:
		k += 1
	nu_cur = levels[k] - level_i
	if nu_cur <= u:
		nu_cur = (levels[k] - level_j) * 1 / nu_cur
	else:
		nu_cur = -1
	if nu_cur > nu:
		nu = nu_cur
		indices = (i, j, k)
	i += 1
	j += 1
	k = max(k, j + 1)
	level_j = levels[j]
	level_i = levels[i]
sys.stdout.write(str(nu))


(n, U) = map(int, input().split())
E = [int(x) for x in input().split()]
E.append(10 ** 100)
k = 0
best = -1
for i in range(n):
	while E[k + 1] - E[i] <= U:
		k += 1
	j = i + 1
	if i < j < k:
		best = max(best, (E[k] - E[j]) / (E[k] - E[i]))
print(best)


def run():
	(n, u) = (int(x) for x in input().split())
	data = [int(x) for x in input().split()]
	uu = 2
	ans = None
	for i in range(n - 2):
		first = data[i]
		second = data[i + 1]
		trgt = u + first
		if data[i + 2] > trgt:
			continue
		while uu < n - 1 and data[uu + 1] <= trgt:
			uu += 1
		third = data[uu]
		a = (third - second) / (third - first)
		if ans is None:
			ans = a
		else:
			ans = max(ans, a)
	if ans is None:
		ans = -1
	print(ans)
run()


(n, u) = map(int, input().split())
e = list(map(int, input().split()))
e = sorted(e)
r = 1
ans = -1
for i in range(n - 2):
	k = e[i + 1] - e[i]
	while r < n and e[r] - e[i] <= u:
		r += 1
	pr = r - 1
	if pr - i >= 2:
		ans = max(ans, (e[pr] - e[i + 1]) / (e[pr] - e[i]))
if ans == -1:
	print(-1)
	exit()
print('%.12f' % ans)


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


(n, u) = map(int, input().split())
a = list(map(int, input().split()))
i = 0
j = 1
f = 1
ma = -1
while not (i == j and i == n - 1):
	if j <= i:
		j += 1
	if j < n - 1:
		if a[j + 1] - a[i] <= u:
			j += 1
		else:
			if j - i >= 2:
				f = 0
				ma = max(ma, (a[j] - a[i + 1]) / (a[j] - a[i]))
			i += 1
	else:
		if j - i >= 2:
			f = 0
			ma = max(ma, (a[j] - a[i + 1]) / (a[j] - a[i]))
		i += 1
if f:
	print(-1)
else:
	print(ma)


(n, U) = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
import bisect

def max_eligible(a, x):
	ind = bisect.bisect_right(a, x)
	if ind <= len(a):
		return a[ind - 1]
	else:
		return -1
max_val = -1
for i in range(n - 2):
	x = a[i] + U
	val1 = max_eligible(a, x)
	if val1 != -1 and val1 != a[i + 1] and (val1 != a[i]):
		val = (val1 - a[i + 1]) / (val1 - a[i])
		max_val = max(max_val, val)
print(max_val)


(n, U) = list(map(int, input().split()))
E = list(map(int, input().split()))
ind_i = 0
prev_ind_k = ind_i + 2
maxi_efficiency = -1
turn = 0
for ind_i in range(0, n - 2):
	ind_j = ind_i + 1
	prev_ind_k = max(prev_ind_k, ind_i + 2)
	Ei = E[ind_i]
	Ej = E[ind_j]
	for ind_k in range(prev_ind_k, n + 1):
		if ind_k == n:
			prev_ind_k = n - 1
			break
		Ek = E[ind_k]
		if Ek - Ei > U:
			prev_ind_k = ind_k - 1
			break
		efficiency = (Ek - Ej) / (Ek - Ei)
		if efficiency > maxi_efficiency:
			maxi_efficiency = efficiency
print(maxi_efficiency)


from sys import stdin, stdout
(n, U) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
k = 0
ans = -1
for i in range(n):
	while k + 1 < n and a[k + 1] - a[i] <= U:
		k += 1
	if k - i < 2:
		continue
	j = i + 1
	cur = (a[k] - a[j]) / (a[k] - a[i])
	ans = max(ans, cur)
print(ans)


(n, u) = [int(x) for x in input().split()]
a = list(map(int, input().split()))
idx = 0
ans = -1
for i in range(n):
	while idx < n - 1 and a[idx + 1] - a[i] <= u:
		idx += 1
	if idx - i < 2:
		continue
	ans = max(ans, (a[idx] - a[i + 1]) / (a[idx] - a[i]))
print(ans)


import sys
(n, u) = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ')]
b = [0] * n
j = 1
for i in range(n):
	while j < n and a[j] - a[i] <= u:
		j += 1
	b[i] = j - i - 1
ans = -1.0
for i in range(n):
	if b[i] > 1:
		ans = max(ans, (a[i + b[i]] - a[i + 1]) / (a[i + b[i]] - a[i]))
print(ans)


(n, U) = [int(c) for c in input().split(' ')]
E = [int(c) for c in input().split(' ')]

def binary_max_search(max_limit):
	(left, right) = (0, n - 1)
	while left < right:
		mid = (left + right) // 2 + 1
		if E[mid] <= max_limit:
			(left, right) = (mid, right)
		else:
			(left, right) = (left, mid - 1)
	return left
max_conversion_rate = -1
for i in range(n - 2):
	k = binary_max_search(U + E[i])
	if k > i + 1:
		temp = (E[k] - E[i + 1]) / (E[k] - E[i])
		if temp > max_conversion_rate:
			max_conversion_rate = temp
print(max_conversion_rate)


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


import bisect
(n, u) = map(int, input().split())
e = list(map(int, input().split()))
ans = -1
for i in range(n):
	j = i + 1
	k = bisect.bisect_right(e, e[i] + u) - 1
	if i < j < k:
		ans = max(ans, (e[k] - e[j]) / (e[k] - e[i]))
print(ans)


import bisect
(n, u) = map(int, input().split())
ans = float(-1)
a = list(map(int, input().split()))
for i in range(0, n - 2, 1):
	x = int(bisect.bisect_left(a, a[i] + u + 1))
	x = x - 1
	if a[x] != a[i] and a[x] != a[i + 1]:
		ans = max(ans, (a[x] - a[i + 1]) * 1.0 / (a[x] - a[i]))
print(ans)


def upper_bound(a, n, i, x):
	l = i
	h = n
	while l < h:
		mid = (l + h) // 2
		if x >= a[mid]:
			l = mid + 1
		else:
			h = mid
	return l
(n, u) = [int(x) for x in input().split()]
a = list(map(int, input().split()))
idx = 0
ans = -1
for i in range(n - 2):
	idx = upper_bound(a, n, i, a[i] + u) - 1
	if idx - i >= 2:
		ans = max(ans, (a[idx] - a[i + 1]) / (a[idx] - a[i]))
print(ans)


(n, U) = [int(i) for i in input().split()]
E = [int(i) for i in input().split()]
k = 0
ans = 0.0
haveAns = False
for i in range(n):
	while k < n and E[k] - E[i] <= U:
		k += 1
	k -= 1
	if i + 2 <= k:
		rate = E[k] - E[i + 1]
		rate /= E[k] - E[i]
		if rate > ans:
			ans = rate
			haveAns = True
if not haveAns:
	print(-1)
else:
	print(ans)


import bisect

def Judge():
	(n, U) = map(int, input().split())
	E = tuple(map(int, input().split()))
	res = -1
	for i in range(n - 2):
		j = i + 1
		k = bisect.bisect_right(E, E[i] + U) - 1
		if k <= j:
			continue
		res = max(res, (E[k] - E[j]) / (E[k] - E[i]))
	return res
print(Judge())


(n, U) = list(map(int, input().split()))
E = list(map(int, input().split()))
E.append(10 ** 20)
E.append(10 ** 20)
E.append(10 ** 20)
start = 0
finish = 1
res = -1
while start < n - 2:
	while E[finish] - E[start] > U and start < n - 2:
		start += 1
	while E[finish + 1] - E[start] <= U and finish + 1 < n:
		finish += 1
	if finish - start > 1 and finish < n and (start < n):
		if E[finish] - E[start] <= U:
			res = max(res, (E[finish] - E[start + 1]) / (E[finish] - E[start]))
	start += 1
print(res)


from bisect import bisect_left

def takeClosest(myList, myNumber):
	pos = bisect_left(myList, myNumber)
	if pos == len(myList):
		return myList[-1]
	else:
		a1 = myList[pos]
		if a1 > myNumber:
			return myList[pos - 1]
		else:
			return myList[pos]
(n, U) = map(int, input().split(' '))
l = list(map(int, input().split(' ')))
ans = -1
i = 0
while i < n - 2:
	a = l[i]
	b = l[i + 1]
	if l[i + 2] > a + U:
		i += 1
	else:
		c = takeClosest(l, a + U)
		ans = max(ans, (c - b) / (c - a))
		i += 1
print(ans)


from bisect import bisect_left as bi
(n, u) = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
c = []
for i in range(n - 1):
	b = bi(a, a[i] + u)
	if b != n:
		if a[b] == a[i] + u:
			b = b + 1
	b = a[b - 1]
	if b - a[i] != 0:
		c.append((b - a[i + 1]) / (b - a[i]))
if len(c) == 0 or max(c) == 0:
	print(-1)
else:
	print(max(c))


(n, u) = map(int, input().split())
e = list(map(int, input().split()))
res = -1
k = 2
for i in range(n - 2):
	j = i + 1
	k = max(k, j + 1)
	while k < n and e[k] - e[i] <= u:
		k += 1
	k -= 1
	if k > j:
		res = max(res, (e[k] - e[j]) / (e[k] - e[i]))
print(res)


import heapq
from bisect import bisect_left, bisect_right
from collections import Counter
from collections import OrderedDict
from collections import deque
from itertools import accumulate, product
import math
R = lambda : map(int, input().split())
(n, u) = R()
arr = list(R())
res = -1
for l in range(n):
	r = bisect_right(arr, arr[l] + u) - 1
	if r - l > 1:
		res = max(res, (arr[r] - arr[l + 1]) / (arr[r] - arr[l]))
print(res)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
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')
mod = 998244353
(n, u) = map(int, input().split())
a = list(map(int, input().split()))
mx = -1
k = 2
for i in range(n - 2):
	j = i + 1
	while k < n:
		if a[k] - a[i] > u:
			break
		k += 1
	if k - 1 > j:
		r = Fraction(a[k - 1] - a[j], a[k - 1] - a[i])
		mx = max(mx, r)
print(float(mx))


import bisect
from itertools import accumulate, count
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
from sys import maxsize
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 isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

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

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

def factors(n):
	fac = set()
	fac.add(1)
	fac.add(n)
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			fac.add(i)
			fac.add(n // i)
	return list(fac)

def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x
from bisect import bisect_left
(n, u) = map(int, input().split())
arr = list(map(int, input().split()))
ans = -1
for i in range(n - 2):
	bi = bisect_left(arr, arr[i] + u)
	if bi == n:
		bi -= 1
	if bi == i + 1:
		continue
	if arr[bi] - u > arr[i]:
		bi -= 1
	if i == bi or i + 1 == bi:
		continue
	ans = max(ans, (arr[bi] - arr[i + 1]) / (arr[bi] - arr[i]))
print(ans)


(n, U) = map(int, input().split())
Ar = list(map(int, input().split()))
R = 0
ans = -1
for i in range(n):
	while R + 1 < n and Ar[R + 1] - Ar[i] <= U:
		R += 1
	if i + 1 < R:
		ans = max((Ar[R] - Ar[i + 1]) / (Ar[R] - Ar[i]), ans)
print(ans)


(n, u) = map(int, input().split())
a = list(map(int, input().split()))
(l, r) = (0, 0)
ans = -1
for i in range(n):
	r = max(l, r)
	while r < n - 1 and a[r + 1] - a[l] <= u:
		r += 1
	if r - l > 1 and a[r] - a[l] <= u:
		ans = max(ans, (a[r] - a[l + 1]) / (a[r] - a[l]))
	l += 1
print(ans)


(nE, U) = [int(x) for x in input().split(' ')]
energies = [int(x) for x in input().split(' ')]
end = 0
best_ratio = -1
for beg in range(nE - 2):
	while end + 1 < nE and energies[end + 1] - energies[beg] <= U:
		end += 1
	if end - beg < 2:
		continue
	new_ratio = (energies[end] - energies[beg + 1]) / (energies[end] - energies[beg])
	best_ratio = max(best_ratio, new_ratio)
if best_ratio == -1:
	print(-1)
else:
	print('%.20f' % best_ratio)


def read_data():
	(n, m) = map(int, input().strip().split())
	a = list(map(int, list(input().strip().split())))
	return (n, m, a)

def find(start, end, v):
	mid = int((start + end) / 2)
	if start == end:
		return start
	if end - start == 1:
		if a[end] <= v:
			return end
		else:
			return start
	if a[mid] == v:
		return mid
	if a[mid] > v:
		return find(start, mid, v)
	else:
		return find(mid, end, v)

def solve():
	val = -1
	for i in range(0, len(a) - 2):
		pos = find(i + 2, len(a) - 1, a[i] + m)
		if a[pos] <= a[i] + m:
			if (a[pos] - a[i + 1]) / (a[pos] - a[i]) > val:
				val = (a[pos] - a[i + 1]) / (a[pos] - a[i])
	return val
(n, m, a) = read_data()
print(solve())


import sys
input = sys.stdin.readline
from bisect import *
(n, U) = map(int, input().split())
E = list(map(int, input().split()))
ans = -1
for i in range(n):
	j = i + 1
	k = bisect_right(E, E[i] + U) - 1
	if k - i >= 2:
		ans = max(ans, (E[k] - E[j]) / (E[k] - E[i]))
print(ans)


import math
import sys
from collections import deque
from fractions import Fraction
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 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 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
(n, k1) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
m = -1
for y in range(1, n - 1):
	i = y - 1
	j = y
	k = binarySearchCount(a, n, a[i] + k1) - 1
	if i == k or j == k:
		continue
	r = Fraction(a[k] - a[j], a[k] - a[i])
	m = max(m, r)
if m == -1:
	print(-1)
else:
	print(float(m))


(n, U) = map(int, input().split())
E = list(map(int, input().split()))
best = -1
k = 0
for i in range(n):
	while k + 1 < n and E[k + 1] - E[i] <= U:
		k += 1
	if k >= i + 2:
		best = max(best, (E[k] - E[i + 1]) / (E[k] - E[i]))
print(best)


import sys
import bisect
input = sys.stdin.readline
(N, U) = map(int, input().split())
Es = list(map(int, input().split()))
ans = -1
for i in range(N - 1):
	Ei = Es[i]
	Ej = Es[i + 1]
	Ek = Es[bisect.bisect_right(Es, Ei + U) - 1]
	if Ek > Ej:
		ans = max(ans, (Ek - Ej) / (Ek - Ei))
print(ans)


import sys
[n, U] = map(int, sys.stdin.readline().strip().split())
E = list(map(int, sys.stdin.readline().strip().split()))
max_eta = -1
k = 2
for i in range(n - 2):
	k = max(k, i + 2)
	if E[k] - E[i] > U:
		continue
	while k + 1 < n and E[k + 1] - E[i] <= U:
		k += 1
	eta = (E[k] - E[i + 1]) / (E[k] - E[i])
	max_eta = max(max_eta, eta)
if max_eta < 0:
	print(max_eta)
else:
	print('{:.10f}'.format(max_eta))


from bisect import bisect_left
(n, u) = map(int, input().split())
arr = [int(x) for x in input().split()]
ans = -1
for i in range(n - 2):
	bi = bisect_left(arr, arr[i] + u)
	if bi == n:
		bi -= 1
	if bi == i + 1:
		continue
	if arr[bi] - u > arr[i]:
		bi -= 1
	if i == bi or i + 1 == bi:
		continue
	ans = max(ans, (arr[bi] - arr[i + 1]) / (arr[bi] - arr[i]))
print(ans)


(N, U) = map(int, input().strip().split())
E = list(map(int, input().strip().split()))
maxu = -1
j = 2
if N < 3:
	print(-1)
for i in range(N - 2):
	j = max(i + 2, j)
	if E[j] - E[i] > U:
		continue
	while j < N and E[j] - E[i] <= U:
		j += 1
	j -= 1
	maxu = max(maxu, (E[j] - E[i + 1]) / (E[j] - E[i]))
print(maxu)


par = input()
par = list(map(int, par.split()))
(n, U) = (par[0], par[1])
E = input()
E = list(map(int, E.split()))
f = -1
idx = 0
for i in range(n - 2):
	while idx < n - 1 and E[idx + 1] <= E[i] + U:
		idx += 1
	if idx - i < 2:
		continue
	else:
		f = max((E[idx] - E[i + 1]) / (E[idx] - E[i]), f)
print(f)


(n, U) = list(map(int, input().strip().split()))
E = list(map(int, input().strip().split()))
mmax = -1
for i in range(0, n - 2):
	j = i + 1
	l = j + 1
	r = n - 1
	while l < r:
		mid = (l + r) // 2
		if E[mid] - E[i] <= U:
			l = mid + 1
		else:
			r = mid - 1
	if E[l] - E[i] <= U:
		cur = (E[l] - E[j]) / (E[l] - E[i])
		mmax = max(mmax, cur)
	elif l - 1 > j and E[l - 1] - E[i] <= U:
		cur = (E[l - 1] - E[j]) / (E[l - 1] - E[i])
		mmax = max(mmax, cur)
print(mmax)


(n, u) = list(map(int, input().split()))
e = list(map(int, input().split()))
max_eff = -1
j = 0
for i in range(n):
	while j < n and e[j] <= e[i] + u:
		j += 1
	if i + 3 <= j:
		max_eff = max(max_eff, (e[j - 1] - e[i + 1]) / (e[j - 1] - e[i]))
print(max_eff)


import sys, math, os.path
from decimal import Decimal
FILE_INPUT = 'c.in'
DEBUG = os.path.isfile(FILE_INPUT)
if DEBUG:
	sys.stdin = open(FILE_INPUT)

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

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

def log(x):
	if DEBUG:
		print(x)
(n, u) = ni()
e = nia()
log(e)
mres = Decimal(-1)
iu = 0
for i in range(n):
	while iu < n - 1 and e[iu + 1] - e[i] <= u:
		iu += 1
	if i < iu - 1:
		j = i + 1
		k = iu
		enew = Decimal(e[k] - e[j]) / Decimal(e[k] - e[i])
		mres = max(enew, mres)
print(mres)


import sys

def read_two_int():
	return map(int, sys.stdin.readline().strip().split(' '))

def fast_solution(n, U, E):
	best = -1
	R = 2
	for i in range(n - 2):
		R = max(R, i + 2)
		while R + 1 < n and E[R + 1] - E[i] <= U:
			R += 1
		if E[R] - E[i] <= U:
			efficiency = float(E[R] - E[i + 1]) / (E[R] - E[i])
			if best is None or efficiency > best:
				best = efficiency
	return best
(n, U) = read_two_int()
E = list(read_two_int())
print(fast_solution(n, U, E))