You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}] consisting of N positive integers.

You are also given a constant K, using which you can perform the following operation on A:
Choose two distinct indices i and j such that A_{i} + A_{j} ≤ K, and remove either A_{i} or A_{j} from A.

Is it possible to obtain an array consisting of only one element using several (possibly, zero) such operations?

------ Input Format ------ 

- The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
- The first line of each test case contains two space-separated integers N and K. 
- The second line contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}.

------ Output Format ------ 

For each test case, print "YES" if it is possible to obtain an array consisting of only one element using the given operation, otherwise print "NO".

You may print each character of the string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).

------ Constraints ------ 

$1 ≤ T ≤ 10^{3}$
$1 ≤ N ≤ 10^{5}$
$1 ≤ A_{i}, K ≤ 10^{9}$
- Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$

----- Sample Input 1 ------ 
3
1 3
1
3 3
2 2 2
4 7
1 4 3 5

----- Sample Output 1 ------ 
YES
NO
YES

----- explanation 1 ------ 
Test case $1$: The length of the array is already $1$.

Test case $2$: There is no way to delete an element from the given array.

Test case $3$: One possible sequence of operations is:

- Choose $i = 1, j = 4$ and remove $A_{j} = 5$. Hence the array becomes $[1, 4, 3]$.
- Choose $i = 2, j = 3$ and remove $A_{i} = 4$. Hence the array becomes $[1, 3]$.
- Choose $i = 1, j = 2$ and remove $A_{i} = 1$. Hence the array becomes $[3]$, which is of length $1$.

Difficulty: MEDIUM
Tags: Constructive algorithms

Data structures

Ad-hoc
Skill types: Data structures

Starter code:

Solutions:
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	x = max(A)
	y = min(A)
	if n == 1:
		print('YES')
	elif x > k:
		print('NO')
	elif x + y <= k:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	d = max(arr)
	e = min(arr)
	if n == 1:
		print('YES')
	elif d > k:
		print('NO')
	elif d + e <= k:
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	b = list(map(int, input().split()))
	c = min(b)
	d = max(b)
	if n == 1:
		print('YES')
	elif d > k:
		print('NO')
	elif c + d <= k:
		print('YES')
	else:
		print('NO')
	t -= 1


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


t = int(input())
while t:
	(n, k) = input().split()
	A = [int(x) for x in input().split()]
	if int(n) > 1:
		A.sort()
		if A[0] + A[-1] <= int(k):
			print('YES')
		else:
			print('NO')
	else:
		print('YES')
	t -= 1


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


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	a.sort()
	if a[0] + a[-1] > k and len(a) > 1:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	(a, b) = map(int, input().split())
	x = list(map(int, input().split()))
	t = min(x)
	max1 = max(x)
	if max1 + t <= b or a == 1:
		print('YES')
	else:
		print('NO')


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


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	print('YES' if min(a) + max(a) <= k or n == 1 else 'NO')


for tc in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	if n == 1:
		print('YES')
	else:
		(mine, maxe) = (10000000000, 0)
		for ele in arr:
			mine = min(mine, ele)
			maxe = max(maxe, ele)
		if mine + maxe <= k:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	nums = list(map(int, input().split()))
	print('YES') if len(nums) == 1 else print('YES') if min(nums) + max(nums) <= k else print('NO')


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


t = int(input())
while t:
	(n, k) = map(int, input().split(' '))
	list1 = list(map(int, input().split(' ')))
	list1.sort()
	if n == 1:
		print('YES')
		t = t - 1
		continue
	if list1[0] + list1[-1] <= k:
		print('YES')
	else:
		print('NO')
	t -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	if n == 1:
		print('YES')
	elif min(a) + max(a) > k:
		print('NO')
	else:
		print('YES')


t = int(input())
for t in range(t):
	(n, k) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	maxm = max(arr)
	minm = min(arr)
	flag = 0
	if n == 1:
		flag = 1
	elif maxm + minm <= k:
		flag = 1
	if flag == 0:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	if n <= 1:
		print('YES')
		continue
	if max(arr) >= k:
		print('NO')
		continue
	if max(arr) + min(arr) > k:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	maxi = max(arr)
	mini = min(arr)
	if n == 1:
		print('YES')
	elif maxi > k:
		print('NO')
	elif maxi + mini <= k:
		print('YES')
	else:
		print('NO')


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


for _ in range(int(input())):
	(N, K) = list(map(int, input().split(' ')))
	lst = list(map(int, input().split(' ')))
	a = min(lst)
	b = max(lst)
	if N == 1:
		print('YES')
	elif b > K:
		print('NO')
	elif a + b <= K:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	ls = list(map(int, input().split()))
	ls.sort()
	if n == 1:
		print('YES')
	elif ls[-1] + ls[0] <= k:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	ls = list(map(int, input().split()))
	if n == 1:
		print('YES')
	else:
		nmax = max(ls)
		nmin = min(ls)
		if nmin + nmax <= k:
			print('YES')
		else:
			print('NO')


for t in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	x = min(l)
	y = max(l)
	if len(l) == 1:
		print('YES')
	elif y > k:
		print('NO')
	elif x + y <= k:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(m, n) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	if len(l) == 1:
		print('YES')
	else:
		c = l[0]
		d = l[1]
		cnt = 0
		c1 = 1
		for i in range(1, len(l)):
			if c + d > n:
				break
			elif c1 + 1 > len(l) - 1:
				cnt += 1
			else:
				c1 += 1
				d = l[c1]
				cnt += 1
		if cnt == len(l) - 1:
			print('YES')
		else:
			print('NO')


N = int(input())
for i in range(N):
	(n, k) = map(int, input().split())
	l = [int(x) for x in input().split()]
	l.sort()
	while True:
		if len(l) == 1:
			print('YES')
			break
		elif l[0] + l[1] <= k:
			l.pop(1)
		else:
			print('NO')
			break


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = list(map(int, input().split()))[:b]
	c.sort()
	sg = c[1:]
	s = True
	for i in sg:
		if c[0] + i > b:
			s = False
			break
		else:
			continue
	if s == True:
		print('YES')
	else:
		print('NO')


for j in range(int(input())):
	(n, k) = map(int, input().split())
	l = []
	l = list(map(int, input().split()))
	l = sorted(l)
	if n == 1:
		print('YES')
	elif l[0] + l[-1] > k:
		print('NO')
	else:
		print('YES')


for t in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	if len(arr) == 1:
		print('YES')
	elif arr[0] + arr[-1] <= k:
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	(n, k) = map(int, input().strip().split())
	l = list(map(int, input().strip().split()))
	x = max(l)
	y = min(l)
	if n == 1:
		print('YES')
	elif x > k:
		print('NO')
	elif x + y <= k:
		print('YES')
	else:
		print('NO')
	t -= 1


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


t = int(input(''))
for _ in range(t):
	(n, k) = map(int, input('').split())
	a = list(map(int, input('').split()))
	a.sort()
	if n == 1:
		print('YES')
	else:
		while a[0] + a[1] <= k:
			a.pop(1)
			if len(a) == 1:
				print('YES')
				break
		else:
			print('NO')


t = int(input())
for t in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	lMax = max(l)
	lMin = min(l)
	if n == 1 or lMin + lMax <= m:
		print('YES')
	elif lMax > m or lMin + lMax > m:
		print('NO')


for _ in range(int(input())):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	if N == 1:
		print('YES')
	else:
		s = min(A) + max(A)
		if s > K:
			print('NO')
		else:
			print('YES')


for _ in range(0, int(input())):
	inp = input().split(' ')
	n = int(inp[0])
	k = int(inp[1])
	array = map(int, input().split(' '))
	if n == 1:
		print('YES')
	else:
		minval = 2 ** 32
		maxval = -1
		for a in array:
			minval = min(minval, a)
			maxval = max(maxval, a)
		if maxval + minval <= k:
			print('YES')
		else:
			print('NO')


T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if n == 1:
		print('YES')
		continue
	minim = maxim = a[0]
	for i in range(1, n):
		minim = min(minim, a[i])
		maxim = max(maxim, a[i])
	if minim + maxim <= k:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	if len(A) == 1:
		print('YES')
	elif max(A) >= k:
		print('NO')
	elif max(A) + min(A) <= k:
		print('YES')
	else:
		print('NO')


T = int(input())
for j in range(0, T):
	temp = input()
	str_list = temp.split()
	N = int(str_list[0])
	K = int(str_list[1])
	temp = input()
	A_s = [int(a) for a in temp.split()]
	if N == 1:
		print('YES')
		continue
	if max(A_s) + min(A_s) > K:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	if n < 2:
		print('YES')
		continue
	if min(lst) + max(lst) <= k:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	m = max(a)
	mi = min(a)
	if n == 1:
		print('YES')
	elif m > k:
		print('NO')
	elif m + mi <= k:
		print('YES')
	else:
		print('NO')
	t = t - 1