Mark is asked to take a group photo of $2n$ people. The $i$-th person has height $h_i$ units.

To do so, he ordered these people into two rows, the front row and the back row, each consisting of $n$ people. However, to ensure that everyone is seen properly, the $j$-th person of the back row must be at least $x$ units taller than the $j$-th person of the front row for each $j$ between $1$ and $n$, inclusive.

Help Mark determine if this is possible.


-----Input-----

The first line contains one integer $t$ ($1\leq t\leq 100$) — the number of test cases. Each test case consists of two lines.

The first line of each test case contains two positive integers $n$ and $x$ ($1\leq n\leq 100$, $1\leq x\leq 10^3$) — the number of people in each row and the minimum difference Mark wants.

The second line of each test case contains $2n$ positive integers $h_1,h_2,\ldots,h_{2n}$ ($1\leq h_i\leq 10^3$) — the height of each person in units.

Note that the sum of $n$ over all test cases is not bounded.


-----Output-----

For each test case, print a single line containing "YES" if Mark could arrange people satisfying his condition and "NO" otherwise.

You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answers).


-----Examples-----

Input
3
3 6
1 3 9 10 12 16
3 1
2 5 2 2 2 5
1 2
8 6
Output
YES
NO
YES


-----Note-----

In the first test case, one possible order is to have the third, fifth, and sixth person on the back row and the second, first, and fourth on the front row. The heights of the people will look like this.

Back

$9$

$12$

$16$

Front

$3$

$1$

$10$

It works because

$h_3-h_2 = 9-3 \geq 6$,

$h_5-h_1 = 12-1\geq 6$, and

$h_6-h_4 = 16-10\geq 6$.

In the second test case, it can be shown there is no way to order people in a way that satisfies the condition.

In the third test case, the only way to arrange people to satisfy the condition is to have the first person on the back row and the second person on the front row.

Difficulty: EASY
Tags: Sorting

Greedy algorithms
Skill types: Sorting

Greedy algorithms

Starter code:

Solutions:
t = int(input())
for i in range(t):
	(n, x) = map(int, input().split(' '))
	h = list(map(int, input().split(' ')))
	h = sorted(h)
	for j in range(0, n):
		if h[n + j] - h[j] < x:
			print('NO')
			break
	else:
		print('YES')


t = int(input())
for i in range(t):
	nx = list(map(int, input().split()))
	(n, x) = (nx[0], nx[1])
	height = sorted(list(map(int, input().split())))
	flag = True
	for i in range(n):
		if height[i + n] - height[i] < x:
			print('NO')
			flag = False
			break
	if flag == True:
		print('YES')


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	ans = 'YES'
	for i in range(n):
		if a[i + n] - a[i] < x:
			ans = 'NO'
			break
	print(ans)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = sorted(map(int, input().split()))
	a = l[:n]
	b = l[n:]
	print('YNEOS'[not all((abs(i - j) >= x for (i, j) in zip(a, b)))::2])


for i in range(int(input())):
	(n, x) = map(int, input().split())
	p = sorted(list(map(int, input().split())))
	(f, b) = (p[:n], p[n:])
	for i in range(n):
		if b[i] - f[i] < x:
			print('NO')
			break
	else:
		print('YES')


tc = int(input())
for t in range(tc):
	(n, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	lst.sort()
	arr = lst[n:]
	bol = True
	for i in range(n):
		if arr[i] - lst[i] < k:
			bol = False
			break
	if bol:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	L = list(map(int, input().split()))
	L.sort()
	A = L[:n]
	B = L[n:]
	found = True
	for i in range(n):
		if B[i] >= A[i] + x:
			pass
		else:
			found = False
			break
	if found:
		print('YES')
	else:
		print('NO')


t = int(input())
c = 0
while c < t:
	n = list(map(int, input().split()))
	h = list(map(int, input().split()))
	h.sort()
	h1 = h[:n[0]]
	h2 = h[n[0]:]
	i = 0
	j = True
	while i < n[0] and j == True:
		if h2[i] - h1[i] >= n[1]:
			j = True
			i = i + 1
		else:
			j = False
	if i == n[0]:
		print('YES')
	else:
		print('NO')
	c = c + 1


t = int(input())
while t:
	(n, x) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	a.sort()
	for i in range(n):
		if a[i + n] - a[i] < x:
			print('NO')
			break
	else:
		print('YES')
	t -= 1


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	a1 = a[:n]
	a2 = a[n:]
	flag = 0
	for i in range(len(a1)):
		if a2[i] - a1[i] < x:
			flag = 1
			break
	if flag == 1:
		print('NO')
	else:
		print('YES')


n = int(input())
for _ in range(n):
	check = 0
	(n, x) = map(int, input().split())
	arr = [*map(int, input().split())]
	arr.sort()
	for i in range(n):
		if arr[n + i] < arr[i] + x:
			check = 1
			break
	if check:
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	(n, x) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	arr.sort()
	(i, j) = (len(arr) // 2 - 1, len(arr) - 1)
	possible = True
	while i > -1:
		dif = arr[j] - arr[i]
		if dif < x:
			possible = False
			break
		i -= 1
		j -= 1
	if possible:
		print('YES')
	else:
		print('NO')


def checkPoss(a, n, x):
	for i in range(n):
		if a[n + i] - a[i] < x:
			return False
	return True
ans = []
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	if checkPoss(a, n, x):
		ans.append('YES')
	else:
		ans.append('NO')
for c in ans:
	print(c)


def solution():
	(n, x) = map(int, input().split())
	h = sorted(list(map(int, input().split())))
	for i in range(n):
		if h[i + n] - h[i] < x:
			print('NO')
			return
	print('YES')
T = int(input())
for i in range(T):
	solution()


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()[:2 * n]))
	arr.sort()
	counter = 0
	k = -n
	for i in range(0, n):
		if arr[k] - arr[i] >= x:
			counter += 1
		k += 1
	if counter == n:
		print('YES')
	else:
		print('NO')


import sys
LI = lambda : list(map(int, sys.stdin.readline().split()))
for _ in range(int(input())):
	lim = LI()
	height = LI()
	n = lim[0]
	x = lim[1]
	height.sort()
	count = 0
	for i in range(n):
		if abs(height[i + n] - height[i]) >= x:
			count += 1
	print('YES' if count == n else 'NO')


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	on = 0
	for i in range(n):
		if l[i + n] - l[i] < x:
			on = 1
			break
	if on == 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = list(map(int, input().split()))
	h = n[1]
	n = n[0]
	l = list(map(int, input().split()))
	l.sort()
	k = n
	for i in range(n):
		if l[k] - l[i] >= h:
			k += 1
			continue
		else:
			print('NO')
			break
	else:
		print('YES')


t = int(input())
for tt in range(t):
	(n, x) = map(int, input().split())
	res = True
	a = list(map(int, input().split()))
	a.sort()
	for i in range(n):
		if a[n + i] - a[i] < x:
			res = False
			break
	if res == True:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	flag = True
	for i in range(n):
		if l[i + n] - l[i] < x:
			flag = False
			print('NO')
			break
	if flag:
		print('YES')


for _ in range(int(input())):
	z = input().split(' ')
	a = int(z[0])
	b = int(z[1])
	c = [int(x) for x in input().split(' ')]
	c.sort()
	j = a
	count = 0
	for i in range(0, a):
		if c[j] - c[i] < b:
			count += 1
		j += 1
	if count > 0:
		print('NO')
	else:
		print('YES')


import sys
for _ in range(int(input())):
	(n, x) = map(int, sys.stdin.readline().split())
	a = list(map(int, sys.stdin.readline().split()))
	a.sort()
	ans = 'YES'
	for i in range(n):
		if a[i + n] - a[i] < x:
			ans = 'NO'
			break
	sys.stdout.write(ans + '\n')


x = int(input())

def cal(n, m, arr):
	arr.sort()
	t = 0
	for i in range(n):
		if arr[i + n] - arr[i] < m:
			t = 1
			break
	if t == 1:
		return 'NO'
	return 'YES'
for jj in range(x):
	(n, m) = [int(i) for i in input().split(' ')]
	p = [int(i) for i in input().split(' ')]
	print(cal(n, m, p))


t = int(input())
for i in range(t):
	(n, x) = list(map(int, input().split()))
	h = list(map(int, input().split()))
	h.sort()
	h1 = h[:n].copy()
	h2 = h[n:].copy()
	t = 0
	for i in range(n):
		if h2[i] >= h1[i] + x:
			continue
		else:
			t = 1
			break
	print('NO' if t else 'YES')


for _ in ' ' * int(input()):
	(n, m) = map(int, input().split())
	l = sorted(map(int, input().split()))
	print(['NO', 'YES'][all((l[i + n] - l[i] >= m for i in range(n)))])


from math import *
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	c = 0
	for i in range(n):
		if abs(l[i] - l[i + n]) >= x:
			c += 1
	if c == n:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(n, x) = map(int, input().split())
	l = [int(x) for x in input().split()]
	l.sort()
	co = 0
	ce = 0
	for j in range(n):
		if l[n + j] - l[j] < x:
			co += 1
		else:
			ce += 1
	if co != 0:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	flag = 0
	for i in range(n, 2 * n):
		if arr[i] - arr[i - n] < x:
			flag = 1
			print('NO')
			break
	if flag == 0:
		print('YES')


T = int(input())
for t in range(T):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	a = sorted(a, reverse=False)
	front = a[:n]
	back = a[n:]
	ans = True
	for i in range(n):
		if front[i] + x <= back[i]:
			continue
		else:
			ans = False
			break
	if not ans:
		print('NO')
	else:
		print('YES')


def check_delta(heights, n, min_delta):
	for j in range(n):
		if heights[n + j] - heights[j] < min_delta:
			print('NO')
			return
	print('YES')
rounds = int(input())
for i in range(rounds):
	(n, min_delta) = list(map(int, input().split(' ')))
	heights = list(map(int, input().split(' ')))
	heights.sort()
	check_delta(heights, n, min_delta)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	h = sorted(map(int, input().split()))
	print('YES' if all((h[n + i] - h[i] >= x for i in range(n))) else 'NO')


t = int(input())
l4 = []
for i in range(t):
	(n, x) = input().split()
	n = int(n)
	x = int(x)
	l1 = []
	l2 = []
	l3 = []
	h = input().split()
	h = list(map(int, h))
	h.sort()
	l1 = h[:n]
	l2 = h[n:]
	l1.sort()
	l2.sort()
	for (i, j) in zip(l1, l2):
		if j - i >= x:
			l3.append(1)
		elif j - i < x:
			l3.append(0)
	if len(l3) == sum(l3):
		l4.append('YES')
	else:
		l4.append('NO')
for i in l4:
	print(i)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split(' '))
	heights = list(map(int, input().split(' ')))
	heights.sort()
	mid = len(heights) // 2
	length = len(heights)
	result = 'YES'
	for i in range(mid, length):
		if heights[i] - heights[i - mid] < x:
			result = 'NO'
			break
	print(result)


ans = []
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	h = sorted(map(int, input().split()))
	h1 = h[:n]
	h2 = h[n:]
	ans += ['YES' if all((h2[i] - h1[i] >= x for i in range(n))) else 'NO']
print(*ans, sep='\n')


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	h = sorted([int(x) for x in input().split()])
	ans = 'YES'
	for (i, j) in zip(h[:n], h[n:]):
		if j - i >= x:
			continue
		else:
			ans = 'NO'
			break
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	a = [int(x) for x in input().split()]
	h = [int(x) for x in input().split()]
	h.sort()
	ans = True
	for i in range(a[0]):
		if h[i] > h[i + a[0]] - a[1]:
			ans = False
	if ans:
		print('YES')
	else:
		print('NO')


t = int(input())
for test in range(t):
	(n, x) = map(int, input().split())
	heights = list(map(int, input().split()))
	heights.sort()
	row1 = heights[:n]
	row2 = heights[n:]
	i = 0
	while i <= n - 1:
		if row2[i] - row1[i] < x:
			print('NO')
			break
		i += 1
	else:
		print('YES')


def solve():
	(n, x) = map(int, input().split())
	a = sorted((int(_) for _ in input().split()))
	for i in range(n):
		if a[i + n] - a[i] < x:
			print('NO')
			return
	print('YES')
for _ in range(int(input())):
	solve()


test = int(input())
for t in range(test):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	f = 0
	for i in range(n):
		if arr[i + n] - arr[i] < x:
			f = 1
			print('NO')
			break
	if f == 0:
		print('YES')


MOD = 10 ** 9 + 7
fac_mem = [1]

def fac(n):
	while len(fac_mem) < n + 1:
		fac_mem.append(fac_mem[-1] * len(fac_mem) % MOD)
	return fac_mem[n]

def perm(n, k):
	return fac(n) * pow(fac(k), MOD - 2, MOD) % MOD

def comb(n, k):
	return fac(n) * pow(fac(k) * fac(n - k) % MOD, MOD - 2, MOD) % MOD

def count(l):
	r = {}
	for i in l:
		r[i] = r.get(i, 0) + 1
	return r

def group(l):
	r = []
	p = None
	c = 0
	for i in l:
		if i == p:
			c += 1
		else:
			r.append((p, c))
			p = i
			c = 1
	if c:
		r.append((p, c))
	return r

class Tree:

	def __init__(self, id):
		self.id = id
		self.parent = None
		self.children = []

	def __repr__(self):
		if self.children:
			return f'{self.id} -> [' + ', '.join((str(c) for c in self.children)) + ']'
		else:
			return f'{self.id}'
for case in range(int(input())):
	(n, x) = [int(j) for j in input().split()]
	a = [int(j) for j in input().split()]
	a = sorted(a)
	possible = True
	for i in range(n):
		if a[i] + x > a[i + n]:
			possible = False
			break
	print(['NO', 'YES'][possible])


import sys
input = lambda : sys.stdin.readline().rstrip()

def solve():
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	for i in range(n):
		if a[i] + x > a[i + n]:
			return 0
	return 1
for __ in range(int(input())):
	print('YES' if solve() else 'NO')


def solve(arr, x, n):
	arr = sorted(arr)
	for i in range(n):
		if arr[i] + x > arr[i + n]:
			return False
	return True
T = int(input())
for _ in range(T):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	res = solve(arr, x, n)
	if res:
		print('YES')
	else:
		print('NO')


def resi():
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	for i in range(n):
		if a[i] + x > a[i + n]:
			print('NO')
			return
	print('YES')
	return
for _ in range(int(input())):
	resi()


def main():
	for t in range(int(input())):
		(n, x) = map(int, input().split())
		a = sorted(list(map(int, input().split())))
		flag = True
		for i in range(n):
			if a[i] + x > a[i + n]:
				flag = False
				break
		print('YES' if flag else 'NO')
main()


t = int(input())
for tc in range(t):
	(n, x) = map(int, input().split())
	h = [int(i) for i in input().split()]
	h.sort()
	ans = 'YES'
	for i in range(n):
		if h[i + n] - h[i] < x:
			ans = 'NO'
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	h = list(map(int, input().split()))
	h.sort()
	ans = 1
	for i in range(n):
		if h[i + n] - h[i] < k:
			ans = 0
	if ans:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(n, x) = map(int, input().split())
	H = [int(k) for k in input().split()]
	H.sort()
	for k in range(n):
		if H[n + k] - H[k] < x:
			print('NO')
			break
	else:
		print('YES')


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	f = True
	for i in range(n):
		if a[i] + x > a[n + i]:
			print('NO')
			f = False
			break
	if f:
		print('YES')


from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	flag = 0
	l.sort()
	for i in range(n):
		if l[i] <= l[i + n] - k:
			pass
		else:
			flag = 1
			break
	if flag:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	v = 1
	for j in range(n):
		if a[n + j] - a[j] < x:
			v = 0
	if v:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	for i in range(n):
		if a[i + n] - a[i] < k:
			print('NO')
			break
	else:
		print('YES')


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	l = sorted(list(map(int, input().split())))
	for i in range(n):
		if l[n + i] - l[i] < m:
			print('NO')
			break
	else:
		print('YES')


for i in range(int(input())):
	(n, x) = map(int, input().split())
	c = sorted((int(j) for j in input().split()))
	f = []
	for j in range(n):
		f = [c.pop()] + f
	k = 0
	for j in range(n):
		if f[j] - c[j] < x:
			k = 1
	print(['YES', 'NO'][k])


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	hi = list(map(int, input().split()))
	hi.sort()
	row = [[], []]
	for i in range(len(hi)):
		if i < n:
			row[0].append(hi[i])
		else:
			row[1].append(hi[i])
	for i in range(n):
		if row[1][i] - row[0][i] < x:
			print('NO')
			break
	else:
		print('YES')


for t in range(int(input())):
	(n, x) = map(int, input().split())
	h = [int(x) for x in input().split()]
	h.sort()
	first = h[:n]
	second = h[n:]
	if all((s - f >= x for (f, s) in zip(first, second))):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	h = list(map(int, input().split()))
	h.sort()
	res = True
	for j in range(n):
		if h[j + n] - h[j] < x:
			res = False
			break
	if res:
		print('YES')
	else:
		print('NO')


import sys
import collections
from math import ceil, gcd, sqrt, log
import bisect
INF = float('inf')
mod = 1000000007

def solve():
	(n, x) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	one = A[0:n]
	two = A[n:]
	ok = 1
	for i in range(n):
		if two[i] - one[i] < x:
			ok = 0
			break
	if ok:
		print('YES')
	else:
		print('NO')
t = int(input())
while t != 0:
	solve()
	t -= 1


for p in range(int(input())):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort()
	b = a[:n]
	(c, f) = (a[n:], 0)
	for i in range(len(b)):
		if c[i] - b[i] < x:
			f = 1
			break
	if f:
		print('NO')
	else:
		print('YES')


def num():
	c = int(input())
	return c

def stri():
	c = str(input())
	return c

def vector():
	c = list(map(int, input().split()))
	return c

def strvector():
	c = list(map(str, input().split()))
	return c
import math

def isprime(num):
	a = 2
	while a <= math.sqrt(num):
		if num % a < 1:
			return False
		a = a + 1
	return num > 1
t = num()
while t > 0:
	t -= 1
	(n, x) = vector()
	arr = vector()
	arr.sort()
	ans = True
	j = n
	for i in range(0, n):
		if arr[j + i] - arr[i] < x:
			ans = False
			break
	print('YES' if ans else 'NO')


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	num = list(map(int, input().split()))
	num.sort()
	for i in range(n):
		if num[n + i] - num[i] < x:
			f = 0
			break
		else:
			f = 1
	if f:
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	(N, X) = map(int, input().split())
	H = list(map(int, input().split()))
	H = sorted(H)
	ans = 'YES'
	for i in range(N):
		if H[N + i] - H[i] < X:
			ans = 'NO'
			break
	print(ans)


for t in range(int(input())):
	(n, x) = map(int, input().split())
	A = [int(i) for i in input().split()]
	A.sort()
	B = A[:][:n]
	C = A[:][n:]
	flag = 1
	for i in range(n):
		if B[i] + x <= C[i]:
			continue
		else:
			flag = 0
			break
	print('YES' if flag else 'NO')


import sys
input = lambda : sys.stdin.readline().strip()
for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	c = sorted(list(map(int, input().split())))
	d = c[:a]
	e = c[a:]
	for i in range(a):
		if e[i] - d[i] < b:
			print('NO')
			break
	else:
		print('YES')


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	(*h,) = map(int, input().split())
	h.sort()
	fl = True
	for i in range(n):
		if h[n + i] - h[i] < x:
			fl = False
	print('YES') if fl else print('NO')


for i in range(int(input())):
	(a, b) = map(int, input().split())
	c = list(map(int, input().split()))
	c.sort()
	d = c[:a]
	c = c[a:]
	count = 0
	for i in range(len(d)):
		if c[i] - b >= d[i]:
			count += 1
	if count == len(d):
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	t -= 1
	(n, x) = [int(x) for x in input().split()]
	l = [int(x) for x in input().split()]
	l.sort()
	flag = 0
	for i in range(n):
		if l[i + n] - l[i] >= x:
			continue
		else:
			flag = 1
			print('NO')
			break
	if flag == 0:
		print('YES')


def solve_one():
	(n, x) = map(int, input().split())
	nums = map(int, input().split())
	nums = sorted(nums)
	for i in range(n):
		if nums[i + n] - nums[i] < x:
			return 'NO'
	return 'YES'
t = int(input())
anss = []
for _ in range(t):
	anss.append(solve_one())
for ans in anss:
	print(ans)


def ss(n, l, k):
	l = sorted(l)
	i = 0
	j = n
	while i < n:
		if l[i] + k <= l[j]:
			i += 1
			j += 1
		else:
			return 'NO'
	return 'YES'
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	print(ss(n, l, k))


from sys import stdin
from math import log, floor, ceil, gcd
inp = lambda : int(stdin.readline())

def ra(typ):
	return list(map(typ, stdin.readline().split()))

def rv(typ):
	return map(typ, stdin.readline().split())

def main():
	for _ in range(inp()):
		(n, x) = rv(int)
		h = ra(int)
		h.sort()
		ans = True
		for i in range(n):
			if h[i + n] - h[i] < x:
				ans = False
				break
		print('YES' if ans else 'NO')
main()


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	d = a[:n]
	a = a[n:]
	k = 0
	for i in range(n):
		if d[i] + x > a[i]:
			print('NO')
			k = 9
			break
	if k == 0:
		print('YES')


for h in range(int(input())):
	(n, m) = map(int, input().split())
	x = list(map(int, input().split()))
	x.sort()
	f = True
	for i in range(n):
		if x[i] + m > x[i + n]:
			f = False
			break
	if f:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(x, y) = input().split()
	x = int(x)
	y = int(y)
	z = list(map(int, input().split()))
	z.sort()
	a = z[:x]
	b = z[x:]
	c = 1
	for i in range(x):
		if b[i] - a[i] >= y:
			pass
		else:
			c = 0
			break
	if c == 1:
		print('YES')
	else:
		print('NO')


import sys

def rall():
	return [x.strip() for x in sys.stdin.readlines()]

def rl():
	return sys.stdin.readline().strip()

def rl_types(types):
	str_list = [x for x in sys.stdin.readline().strip().split(' ')]
	return [types[i](str_list[i]) for i in range(len(str_list))]

def pr(something=''):
	sys.stdout.write(str(something) + '\n')

def pra(array):
	sys.stdout.write(' '.join([str(x) for x in array]) + '\n')
NT = int(rl())
for ti in range(NT):
	(n, x) = list(map(int, rl().split(' ')))
	array = sorted(list(map(int, rl().split(' '))))
	l = len(array) // 2
	front = array[:l]
	back = array[l:]
	pr('YES' if all([a + x <= b for (a, b) in zip(front, back)]) else 'NO')


import sys
t = int(sys.stdin.readline())
for i in range(t):
	(n, x) = map(int, input().split())
	lst = list(map(int, input().split()))
	lst.sort()
	e = 0
	ind = 2 * n - 1
	for j in range(n - 1, -1, -1):
		d = lst[ind] - lst[j]
		ind -= 1
		if d < x:
			e += 1
			break
	if e > 0:
		print('NO')
	else:
		print('YES')


def main():
	(n, x) = list(map(int, input().split()))
	h = list(map(int, input().split()))
	h.sort()
	firstPart = h[:n]
	secondPart = h[n:]
	flag = True
	for (i, j) in zip(firstPart, secondPart):
		if j - i < x:
			flag = False
	if not flag:
		print('NO')
	else:
		print('YES')
t = int(input())
for i in range(t):
	main()


for xyz in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	count = 0
	for i in range(n):
		if arr[i] + x > arr[i + n]:
			count += 1
			break
	if count == 0:
		print('YES')
	else:
		print('NO')


from math import *
from bisect import *
from heapq import *
from collections import *
from functools import *
x = int(input())

def check(li, x):
	li.sort()
	for i in range(len(li) >> 1):
		if li[i + len(li) // 2] - li[i] < x:
			return 'NO'
	return 'YES'
for i in range(x):
	(n, x) = map(int, input().split())
	li = list(map(int, input().split()))
	print(check(li, x))


out = []
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = [int(i) for i in input().split()]
	a.sort()
	for i in range(n):
		if a[i] + x > a[i + n]:
			out.append('NO')
			break
	else:
		out.append('YES')
for i in out:
	print(i)


a = int(input())
for i in range(a):
	(b, c) = map(int, input().split())
	d = sorted(map(int, input().split()))
	f = 0
	for i in range(b):
		if d[i] + c > d[i + b]:
			f = 1
	if f == 1:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	ans = 'YES'
	for j in range(n):
		if l[j + n] - l[j] < x:
			ans = 'NO'
			break
	print(ans)


t = int(input())
for q in range(t):
	(n, k) = [int(x) for x in input().split()]
	lst = [int(x) for x in input().split()]
	lst = sorted(lst)
	da = True
	for i in range(n):
		if lst[i + n] - lst[i] < k:
			da = False
	if da:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	h = list(map(int, input().split()))
	h.sort()
	count = 0
	for i in range(n):
		if h[i + n] - h[i] < x:
			count = 1
			break
	if count == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, x) = [int(x) for x in input().split()]
	heights = [int(x) for x in input().split()]
	heights.sort()
	h1 = heights[:n]
	h2 = heights[n:]
	result = 'YES'
	for i in range(n):
		if h2[i] - h1[i] < x:
			result = 'NO'
			break
	print(result)