There are two $n$-element arrays of integers, $A$ and $B$. Permute them into some $A^{\prime}$ and $B^{\prime}$ such that the relation $A^{\prime}[i]+B^{\prime}[i]\ge k$ holds for all $i$ where $0\leq i<n$. 

There will be $q$ queries consisting of $A$, $B$, and $k$. For each query, return YES if some permutation $A^{\prime}$ , $B^{\prime}$  satisfying the relation exists.  Otherwise, return NO. 

Example 

$A=[0,1]$ 

$B=[0,2]$ 

$k=1$   

A valid $A^{\prime}$,$B^{\prime}$ is $A^{\prime}=[1,0]$and $B^{\prime}=[0,2]$:$1+0\geq1$  and $0+2\geq1$.  Return YES.

Function Description  

Complete the twoArrays function in the editor below.  It should return a string, either YES or NO.  

twoArrays has the following parameter(s):  

int k: an integer  
int A[n]: an array of integers  
int B[n]: an array of integers   

Returns 

- string: either YES or NO  

Input Format

The first line contains an integer $q$, the number of queries. 

The next $q$ sets of $3$ lines are as follows:

The first line contains two space-separated integers $n$ and $k$, the size of both arrays $A$ and $B$, and the relation variable.
The second line contains $n$ space-separated integers $A[i]$.
The third line contains $n$ space-separated integers $B[i]$.

Constraints

$1\leq q\leq10$
$1\leq n\leq1000$
$1\leq k\leq10^9$
$0\le A[i],B[i]\le10^9$

Sample Input
STDIN       Function
-----       --------
2           q = 2
3 10        A[] and B[] size n = 3, k = 10
2 1 3       A = [2, 1, 3]
7 8 9       B = [7, 8, 9]
4 5         A[] and B[] size n = 4, k = 5
1 2 2 1     A = [1, 2, 2, 1]
3 3 3 4     B = [3, 3, 3, 4]

Sample Output
YES
NO

Explanation

There are two queries:

Permute these into $A^{\prime}=[1,2,3] $and $B^{\prime}=[9,8,7] $ so that the following statements are true:

$A[0]+B[1]=1+9=10\ge k$      
$A[1]+B[1]=2+8=10\ge k$
$A[2]+B[2]=3+7=10\geq k$  

$A=[1,2,2,1]$, $B=[3,3,34]$, and $k=5$. To permute $A$ and $B$ into a valid $A^{\prime}$ and $B^{\prime}$, there must be at least three numbers in $A$ that are greater than $1$.

Difficulty: EASY
Tags: Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
def isGood(listA, listB, k):
	n = len(listA)
	listA.sort()
	listB.sort(reverse=True)
	for i in range(n):
		if listA[i] + listB[i] < k:
			return False
	return True
T = int(input().strip())
for i in range(T):
	[n, k] = [int(x) for x in input().strip().split()]
	listA = [int(x) for x in input().strip().split()]
	listB = [int(x) for x in input().strip().split()]
	if isGood(listA, listB, k):
		print('YES')
	else:
		print('NO')


import sys
f = sys.stdin
T = int(f.readline())
while T:
	(N, K) = map(int, f.readline().split())
	A = list(map(int, f.readline().split()))
	B = list(map(int, f.readline().split()))
	A.sort()
	B.sort()
	B.reverse()
	flag = 0
	for i in range(len(A)):
		if A[i] + B[i] >= K:
			flag += 1
	if flag == i + 1:
		print('YES')
	else:
		print('NO')
	T -= 1


import sys

def main():
	line = sys.stdin.readline()
	t = int(line)
	for testcase in range(t):
		line = sys.stdin.readline()
		vals = [int(i) for i in line.split()]
		k = vals[1]
		line = sys.stdin.readline()
		alist = map(int, line.split())
		line = sys.stdin.readline()
		blist = map(int, line.split())
		alist = sorted(alist)
		blist = sorted(blist, reverse=True)
		isok = True
		for (ai, bi) in zip(alist, blist):
			if ai + bi < k:
				isok = False
				break
		if isok == True:
			print('YES')
		else:
			print('NO')
main()


def two_arrays(a, b, k):
	a_inc = sorted(a)
	b_dec = sorted(b, reverse=True)
	for i in range(len(a)):
		if a_inc[i] + b_dec[i] < k:
			return 'NO'
	return 'YES'
num_test_cases = int(input())
while num_test_cases > 0:
	num_test_cases -= 1
	(n, k) = [int(item) for item in input().split()]
	a = [int(num) for num in input().split()]
	b = [int(num) for num in input().split()]
	print(two_arrays(a, b, k))


t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a = sorted(a)
	b = sorted(b, reverse=True)
	ans = True
	for p in range(n):
		if a[p] + b[p] < k:
			ans = False
			break
	if ans:
		print('YES')
	else:
		print('NO')


def mergeSort(A):
	if len(A) <= 1:
		return A
	mid = int(len(A) / 2)
	A_left = mergeSort(A[:mid])
	A_right = mergeSort(A[mid:])
	return merge(A_left, A_right)

def merge(A, B):
	A_i = 0
	B_i = 0
	n = len(A + B)
	result = []
	A = A[:] + [float('inf')]
	B = B[:] + [float('inf')]
	while len(result) < n:
		if A[A_i] > B[B_i]:
			result.append(B[B_i])
			B_i = B_i + 1
		else:
			result.append(A[A_i])
			A_i = A_i + 1
	return result

def isPossible(A, B, k):
	n = len(A)
	A = mergeSort(A)
	B = mergeSort(B)
	B = B[::-1]
	for i in range(n):
		if A[i] + B[i] < k:
			return 'NO'
	return 'YES'
T = int(input())
array_param = []
array = []
for i in range(T):
	a_input = list(map(int, input().split(' ')))
	array_param.append(a_input)
	array_A = list(map(int, input().split(' ')))
	array_B = list(map(int, input().split(' ')))
	array.append(array_A)
	array.append(array_B)
for i in range(T):
	A = array[2 * i]
	B = array[2 * i + 1]
	k = array_param[i][1]
	print(isPossible(A, B, k))


T = int(input())
A_d = {}
B_d = {}
K_d = {}
N_d = {}
for i in range(T):
	N = input()
	A = input()
	B = input()
	(N, K) = N.split()
	N = int(N)
	K = int(K)
	A = A.split()
	B = B.split()
	A = [int(a) for a in A]
	B = [int(b) for b in B]
	A_d[i] = A
	B_d[i] = B
	K_d[i] = K
	N_d[i] = N
for i in range(T):
	A = A_d[i]
	B = B_d[i]
	K = K_d[i]
	N = N_d[i]
	C = 0
	A.sort()
	B.sort()
	B.reverse()
	j = -1
	for a in A:
		j += 1
		if j < N:
			while a + B[j] < K and j < N - 1:
				j += 1
		if j < N:
			if a + B[j] >= K:
				C += 1
	if C == N:
		print('YES')
	else:
		print('NO')


def main():
	testcase = int(input())
	for i in range(0, testcase):
		(size, maxsum) = [int(z) for z in input().split()]
		up = [int(x) for x in input().split()]
		down = [int(y) for y in input().split()]
		print(test(up, down, maxsum))

def test(x, y, maxsum):
	x.sort()
	y.sort(reverse=True)
	for j in range(0, len(x)):
		if x[j] + y[j] < maxsum:
			return 'NO'
	return 'YES'
main()


T = int(input())
i = 1
t = 1
while t <= int(T):
	NK = input().split()
	N = int(NK[0])
	K = int(NK[1])
	a = input().split()
	A = []
	for item in a:
		A.append(int(item))
	b = input().split()
	B = []
	for item in b:
		B.append(int(item))
	for j in range(len(A)):
		lst = []
		for m in range(len(B)):
			if A[j] + B[m] >= K:
				lst.append(B[m])
		if len(lst) >= 1:
			B.remove(min(lst))
	if len(B) == 0:
		print('YES')
	else:
		print('NO')
	i = i + 3
	t = t + 1


T = int(input())
for t in range(0, T):
	(N, K) = [int(x) for x in input().strip().split(' ')]
	A = sorted([int(x) for x in input().strip().split(' ')])
	B = sorted([int(x) for x in input().strip().split(' ')])
	OK = True
	for i in range(0, N):
		if A[i] + B[N - i - 1] < K:
			OK = False
			break
	if OK:
		print('YES')
	else:
		print('NO')


import sys

def isPossible(A, B, K, N):
	A.sort()
	B.sort()
	res = True
	for i in range(N):
		if A[i] + B[N - 1 - i] < K:
			res = False
			break
	return res
T = int(input())
for idx in range(T):
	(N, K) = [int(i) for i in input().strip().split()]
	A = [int(i) for i in input().strip().split()]
	B = [int(i) for i in input().strip().split()]
	res = isPossible(A, B, K, N)
	if res:
		print('YES')
	else:
		print('NO')


def pairNumbers(first, second, n, m):
	paired = True
	for i in range(0, m):
		if first[i] + second[i] >= n:
			paired = True
		else:
			paired = False
			break
	return paired

def twoArrays(first, second, n, m):
	first.sort()
	second.sort(reverse=True)
	if pairNumbers(first, second, n, m) == True:
		print('YES')
	else:
		print('NO')
n = int(input())
for i in range(0, n):
	sizeAndTarget = input().split()
	array_size = int(sizeAndTarget[0])
	target = int(sizeAndTarget[1])
	first_array = input().split()
	second_array = input().split()
	rfirst = [int(i) for i in first_array]
	rsecond = [int(i) for i in second_array]
	twoArrays(rfirst, rsecond, target, array_size)


for i in range(int(input())):
	K = int(input().split()[1])
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	A.sort()
	B.sort()
	B.reverse()
	for j in range(len(A)):
		if A[j] + B[j] < K:
			print('NO')
			break
	else:
		print('YES')


def check():
	(N, K) = list(map(int, input().split()))
	A = sorted(list(map(int, input().split())))
	B = sorted(list(map(int, input().split())), reverse=True)
	z = zip(A, B)
	for (a, b) in z:
		if a + b < K:
			return False
	return True

def main():
	T = int(input())
	for i in range(T):
		if check():
			print('YES')
		else:
			print('NO')
main()


t = int(input())
for i in range(1, t + 1):
	input1 = input()
	input1 = input1.split()
	N = int(input1[0])
	k = int(input1[1])
	A = input()
	B = input()
	A = A.split()
	B = B.split()
	A = [int(x) for x in A]
	B = [int(x) for x in B]
	A.sort()
	B.sort()
	A.reverse()
	count = 0
	for j in range(0, N):
		if A[j] + B[j] >= k:
			count = count + 1
	if count == N:
		print('YES')
	else:
		print('NO')


import functools
t = int(input())
for test in range(0, t):
	(n, k) = map(int, input().split())
	a = sorted(map(int, input().split()))
	b = sorted(map(int, input().split()), reverse=True)
	ans = functools.reduce(lambda u, v: u and v, [u + v >= k for (u, v) in zip(a, b)])
	print('YES' if ans else 'NO')


def find_ways():
	num_lines = int(input())
	arr0 = []
	arr1 = []
	arr2 = []
	for i in range(num_lines):
		arr0.append(int(input().strip().split()[1]))
		arr1.append([int(x) for x in str(input()).strip().split(' ')])
		arr2.append([int(x) for x in str(input()).strip().split(' ')])
	for i in range(len(arr1)):
		find_satisfies(arr1[i], arr2[i], arr0[i])

def find_satisfies(arr1, arr2, total):
	arr1 = sorted(arr1)
	arr2 = sorted(arr2, reverse=True)
	failed = False
	for i in range(len(arr1)):
		if arr1[i] + arr2[i] < total:
			failed = True
			break
	print('NO' if failed else 'YES')

def main():
	find_ways()
main()


t = int(input())
for p in range(t):
	(n, k) = map(int, input().split())
	a_arr = map(int, input().split())
	b_arr = map(int, input().split())
	a_arr = sorted(a_arr, reverse=True)
	b_arr = sorted(b_arr)
	res = True
	for i in range(n):
		if a_arr[i] + b_arr[i] < k:
			res = False
			break
	if res:
		print('YES')
	else:
		print('NO')


cases = int(input())
ans = 'YES'
result = []
j = 0
while j < cases:
	result.append(ans)
	temp = input()
	temp = temp.split(' ')
	array_len = int(temp[0])
	sum_val = int(temp[1])
	array_A = input()
	array_A = array_A.split(' ')
	array_B = input()
	array_B = array_B.split(' ')
	i = 0
	while i < array_len:
		array_A[i] = int(array_A[i])
		array_B[i] = int(array_B[i])
		i += 1
	array_A.sort()
	array_B.sort()
	array_B.reverse()
	i = 0
	while i < array_len:
		if array_A[i] + array_B[i] < sum_val:
			result[j] = 'NO'
			i = array_len
		i += 1
	j += 1
i = 0
while i < cases:
	print(result[i])
	i += 1


x = input()
x = int(x)
for i in range(x):
	z = input()
	z = z.split()
	length = int(z[0])
	k = int(z[1])
	a = input()
	a = a.split()
	for jan in range(length):
		a[jan] = int(a[jan])
	b = input()
	b = b.split()
	for jin in range(length):
		b[jin] = int(b[jin])
	a.sort()
	b.sort()
	b.reverse()
	answer = True
	for index in range(length):
		if a[index] + b[index] < k:
			print('NO')
			break
	else:
		print('YES')


import sys
T = int(sys.stdin.readline())
while T > 0:
	(N, K) = [int(x) for x in sys.stdin.readline().split()]
	arr1 = [int(x) for x in sys.stdin.readline().split()]
	arr2 = [int(x) for x in sys.stdin.readline().split()]
	arr1 = sorted(arr1, reverse=True)
	arr2 = sorted(arr2)
	possible = True
	for (x, y) in zip(arr1, arr2):
		if x + y < K:
			possible = False
			break
	print('YES' if possible else 'NO')
	T -= 1


from itertools import permutations

def check(s2, s3, K):
	FLAG = True
	if max(s2) > max(s3):
		s2 = sorted(s2, reverse=True)
		s3 = sorted(s3)
	else:
		s2 = sorted(s2)
		s3 = sorted(s3, reverse=True)
	L = [True if s2[t] + s3[t] >= K else False for t in range(len(s2))]
	if all(L):
		print('YES')
		FLAG = False
	if FLAG:
		print('NO')
Test_cases = int(input())
for i in range(Test_cases):
	input1 = input()
	s1 = [int(i) for i in input1.split() if i.isdigit()]
	K = s1[1]
	N = s1[0]
	input2 = input()
	s2 = [int(i) for i in input2.split() if i.isdigit()]
	input3 = input()
	s3 = [int(i) for i in input3.split() if i.isdigit()]
	check(s2, s3, K)


t = int(input())
for i in range(t):
	(n, k) = input().split()
	(n, k) = [int(n), int(k)]
	a = input().split()
	a = [int(a[j]) for j in range(n)]
	b = input().split()
	b = [int(b[j]) for j in range(n)]
	count = 0
	nlist = []
	for j in range(n):
		if k >= b[j]:
			c = k - b[j]
			try:
				dex = a.index(c)
				del a[dex]
			except:
				nlist.append(b[j])
				continue
		else:
			count += 1
	if nlist == []:
		print('YES')
	else:
		for j in range(len(nlist)):
			try:
				c = min(filter(lambda x: x > k - nlist[j], a))
				del a[a.index(c)]
			except:
				print('NO')
				break
		if a == [] or count == len(a):
			print('YES')


def main():
	test_cases = int(input())
	for i in range(0, test_cases):
		total = int(input().split(' ')[1])
		A = list(map(int, input().split(' ')))
		B = list(map(int, input().split(' ')))
		B.sort()
		A.sort(reverse=True)
		matches_up = True
		for i in range(0, len(A)):
			if A[i] + B[i] < total:
				matches_up = False
				break
		if matches_up:
			print('YES')
		else:
			print('NO')
main()


m = int(input())
for x in range(m):
	raw_l = input().split()
	n = int(raw_l[0])
	k = int(raw_l[1])
	a_raw = input().split()
	b_raw = input().split()
	a = []
	b = []
	for i in range(n):
		a.append(int(a_raw[i]))
		b.append(int(b_raw[i]))
	a.sort()
	b.sort()
	for i in range(n):
		if a[i] + b[n - i - 1] >= k:
			pass
		else:
			print('NO')
			break
	else:
		print('YES')


class Graph:

	def __init__(self, n):
		self.vertices = ['s'] + [i for i in range(n)] + ['t']
		self.edges = {i: ['s'] for i in range(n // 2)}
		self.edges.update({i: ['t'] for i in range(n // 2, n)})
		self.edges.update({'s': [i for i in range(n // 2)]})
		self.edges.update({'t': [i for i in range(n // 2, n)]})

	def maxMatch(self):
		n = len(self.vertices) - 2
		cap = {}
		used = {}
		for i in self.edges:
			for j in self.edges[i]:
				cap[i, j] = 1
				used[i, j] = 0
		s = [('s', None)]
		visited = {'s': 1}
		while True:
			good = False
			path = {}
			while len(s) > 0:
				curr = s.pop(-1)
				path[curr[0]] = curr[1]
				if curr[0] == 't':
					good = True
					break
				for i in self.edges[curr[0]]:
					if i not in visited and cap[curr[0], i] - used[curr[0], i] > 0:
						s.append((i, curr[0]))
						visited[i] = 1
			if not good:
				count = 0
				for i in range(n // 2):
					for j in range(n // 2, n):
						if used[i, j] == 1:
							count += 1
				return count
			count = 0
			curr = 't'
			last = None
			while curr != 's':
				count += 1
				curr = path[curr]
			return count
T = int(input())
for i in range(T):
	(n, K) = [int(j) for j in input().split()]
	(A, B) = [[int(j) for j in input().split()] for i in range(2)]
	A.sort()
	B.sort()
	good = True
	for j in range(n):
		if A[j] + B[-j - 1] < K:
			good = False
			break
	if good:
		print('YES')
		continue
	g = Graph(2 * n)
	for j in range(n):
		for k in range(n):
			if A[j] + B[k] >= K:
				g.edges[j].append(n + k)
				g.edges[n + k].append(j)
	m = g.maxMatch()
	if m == n:
		print('YES')
	else:
		print('NO')


import sys
from collections import deque
import heapq
from math import *
from itertools import *
PI = pi
INF = 1000000000

def gl():
	return input()

def gs():
	return (x for x in input().split())

def gi():
	return int(input())

def gis():
	return [int(x) for x in input().split()]

def gf():
	return float(input())

def gfs():
	return [float(x) for x in input().split()]

def even(x):
	return x % 2 == 0

def odd(x):
	return x % 2 == 1

def dbg(s):
	print(s, file=sys.stderr)
cases = gi()
for case in range(cases):
	(N, K) = gis()
	A = gis()
	B = gis()
	A.sort()
	B = list(reversed(sorted(B)))
	for (i, j) in zip(A, B):
		if i + j < K:
			print('NO')
			break
	else:
		print('YES')


ncases = int(input())
for x in range(0, ncases):
	line = input().split()
	nelements = int(line[0])
	ssum = int(line[1])
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l1.sort()
	l2.sort()
	res = True
	for y in range(0, nelements):
		if l1[y] + l2[nelements - y - 1] < ssum:
			res = False
			break
	if res:
		print('YES')
	else:
		print('NO')


import sys

def nextLine():
	return sys.stdin.readline().strip()
tests = int(nextLine())
for _ in range(tests):
	(n, k) = [int(s) for s in nextLine().split(' ')]
	A = [int(s) for s in nextLine().split(' ')]
	A.sort()
	B = [int(s) for s in nextLine().split(' ')]
	B.sort(reverse=True)
	C = [sum(x) for x in zip(A, B)]
	if min(C) < k:
		print('NO')
	else:
		print('YES')


def solve(a, b, k):
	for (x, y) in zip(sorted(a), sorted(b, reverse=True)):
		if x + y < k:
			return 'NO'
	return 'YES'

def main():

	def getints():
		return [int(x) for x in input().split()]
	for i in range(getints()[0]):
		(n, k) = getints()
		a = getints()
		b = getints()
		print(solve(a, b, k))
main()


def akb(a, b, n, k):
	a.sort()
	b.sort()
	i = 0
	j = n - 1
	while i <= j:
		if a[i] + b[j] >= k:
			i += 1
			j -= 1
		elif a[i] + b[j] < k:
			return 'NO'
	return 'YES'

def yn():
	T = int(input())
	for l in range(T):
		nk = [int(z) for z in input().split()]
		k = nk.pop()
		n = nk.pop()
		a = [int(x) for x in input().split()]
		b = [int(y) for y in input().split()]
		ans = akb(a, b, n, k)
		print(ans)
yn()


t = int(input())
for i in range(t):
	(size, K) = [int(i) for i in input().strip().split()]
	A = [int(i) for i in input().strip().split()]
	B = [int(i) for i in input().strip().split()]
	A.sort()
	B.sort()
	result = 'YES'
	for a in A:
		for b in B:
			if a + b >= K:
				B.remove(b)
				break
		else:
			result = 'NO'
		if result == 'NO':
			break
	print(result)


T = int(input())
for t in range(T):
	k = int(input().split()[1])
	a = input().split()
	b = input().split()
	a = map(int, a)
	b = map(int, b)
	a = sorted(a)
	b = sorted(b)
	b = b[::-1]
	sol = 'YES'
	for i in range(len(a)):
		if a[i] + b[i] < k:
			sol = 'NO'
			break
	print(sol)


def solve(l, k):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort(reverse=1)
	for i in range(0, l):
		if a[i] + b[i] < k:
			print('NO')
			return
	print('YES')
	return
t = int(input())
for i in range(0, t):
	(l, k) = map(int, input().split())
	solve(l, k)


import sys

def main():
	t = int(sys.stdin.readline())
	while t > 0:
		ln = sys.stdin.readline()
		ls = ln.split(' ')
		n = int(ls[0])
		k = int(ls[1])
		a = sys.stdin.readline().strip().split(' ')
		b = sys.stdin.readline().strip().split(' ')
		for j in range(len(a)):
			a[j] = int(a[j])
		for j in range(len(b)):
			b[j] = int(b[j])
		a.sort()
		b.sort()
		b.reverse()
		i = 0
		while n > 1 and a[i] == a[i + 1]:
			i = i + 1
		if int(b[i]) + int(a[i]) >= k:
			print('YES')
		else:
			print('NO')
		t = t - 1
main()


t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a.sort()
	b.sort(reverse=True)
	yes = True
	for j in range(n):
		if a[j] + b[j] < k:
			yes = False
			break
	print('YES' if yes else 'NO')


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(map(int, input().split()))
	b = sorted(map(int, input().split()))
	for val in a:
		for i in range(len(b)):
			if val + b[i] >= k:
				b.pop(i)
				break
	print('NO' if b else 'YES')


cases = int(input())
for case in range(cases):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort(reverse=True)
	print('YES' if all((x + y >= k for (x, y) in zip(a, b))) else 'NO')


def check(a, b, n):
	for i in range(0, n):
		if a[i] + b[i] < k:
			print('NO')
			return
	print('YES')
	return
t = int(input())
for i in range(0, t):
	a = input().split()
	n = int(a[0])
	k = int(a[1])
	a = input().split()
	b = input().split()
	a = [int(x) for x in a]
	b = [int(x) for x in b]
	a.sort()
	b.sort()
	b.reverse()
	check(a, b, n)


t = int(input())
for testnum in range(t):
	(n, k) = [int(val) for val in input().split()]
	a1 = [int(val) for val in input().split()]
	a2 = [int(val) for val in input().split()]
	a1 = list(sorted(a1))
	a2 = list(sorted(a2, reverse=True))
	test = [a1[i] + a2[i] for i in range(len(a1))]
	output = 'YES' if k <= min(test) else 'NO'
	print(output)


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	(N, K) = list(map(int, sys.stdin.readline().split()))
	A = sorted(map(int, sys.stdin.readline().split()))
	B = sorted(map(int, sys.stdin.readline().split()))
	for (a, b) in zip(A, reversed(B)):
		if a + b < K:
			print('NO')
			break
	else:
		print('YES')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split(' '))
	a = sorted(map(int, input().split(' ')))
	b = sorted(map(int, input().split(' ')), key=lambda x: -x)
	answer = 'YES' if all([a[i] + b[i] >= k for i in range(n)]) else 'NO'
	print(answer)


def check(arA, arB, K):
	arA = sorted(arA)
	arB = sorted(arB, reverse=True)
	for i in range(len(arA)):
		if arA[i] + arB[i] < K:
			print('NO')
			return 0
	print('YES')
	return 0

def main():
	T = int(input())
	for i in range(T):
		inputs = input().rstrip().split()
		N = int(inputs[0])
		K = int(inputs[1])
		arA = map(int, input().rstrip().split())
		arB = map(int, input().rstrip().split())
		check(arA, arB, K)
	return 0
main()


nn = int(input())
for i in range(0, nn):
	(n, k) = list(map(int, input().split()))
	vec_a = list(map(int, input().split()))
	vec_b = list(map(int, input().split()))
	vec_a.sort()
	vec_b.sort(reverse=True)
	i = 0
	j = 0
	answer = True
	while i < n and j < n:
		if vec_a[i] + vec_b[j] < k:
			answer = False
			break
		i += 1
		j += 1
	if answer:
		print('YES')
	else:
		print('NO')


def get():
	inp = input().strip().split()
	nums = [int(x) for x in inp]
	return nums
for i in range(int(input())):
	[n, k] = get()
	a = sorted(get())
	b = sorted(get(), reverse=True)
	ans = 'YES'
	for t in range(n):
		if a[t] + b[t] < k:
			ans = 'NO'
		if ans == 'NO':
			break
	print(ans)


T = int(input().strip())
for i in range(0, T):
	K = list(map(int, input().strip().split(' ')))[1]
	A = list(map(int, input().strip().split(' ')))
	B = list(map(int, input().strip().split(' ')))
	A.sort()
	B.sort()
	for a in A:
		for b in B:
			if a + b >= K:
				B.remove(b)
				break
	if len(B) == 0:
		print('YES')
	else:
		print('NO')


n = int(input())
for z in range(n):
	a = [int(i) for i in input().split(' ')]
	k = a[1]
	b = [int(i) for i in input().split(' ')]
	c = [int(i) for i in input().split(' ')]
	b.sort()
	c.sort(reverse=True)
	d = 0
	for j in range(a[0]):
		if b[j] + c[j] >= k:
			d += 1
	if d == a[0]:
		print('YES')
	else:
		print('NO')


import fileinput

def CanArraysBePermutedToHaveCorrespondingSumsMoreThankK(arr1, arr2, k):
	arr1 = sorted(arr1)
	arr2 = sorted(arr2, reverse=True)
	for j in range(len(arr1)):
		if arr1[j] + arr2[j] < k:
			return False
	return True

def main():
	input_iter = fileinput.input()
	first_line = next(input_iter)
	for i in range(int(first_line)):
		(n, k) = next(input_iter).split()
		n = int(n)
		k = int(k)
		arr1 = [int(x) for x in next(input_iter).split()]
		arr2 = [int(x) for x in next(input_iter).split()]
		print('YES' if CanArraysBePermutedToHaveCorrespondingSumsMoreThankK(arr1, arr2, k) else 'NO')
main()


test = int(input())
for i in range(test):
	calnum = input().split()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for n in range(int(calnum[0])):
		x = None
		if int(min(b)) + int(max(a)) < int(calnum[1]):
			x = 'NO'
			print(x)
			break
		else:
			b.remove(min(b))
			a.remove(max(a))
	if x == None:
		print('YES')


tests = int(input())
out = str()
for i in range(tests):
	(n, k) = [int(s) for s in input().split()]
	L1 = sorted([int(s) for s in input().split()])
	L2 = sorted([int(s) for s in input().split()])[::-1]
	test = True
	for i in range(n):
		if L1[i] + L2[i] < k:
			test = False
			break
	out += 'YES' if test else 'NO'
	out += '\n'
print(out[:-1])


import sys
from functools import reduce
from operator import and_
raw_input = sys.stdin.readline

def test_case():
	(N, K) = [int(i) for i in raw_input().split()]
	A = sorted([int(i) for i in raw_input().split()])
	B = sorted([int(i) for i in raw_input().split()], reverse=True)
	w = reduce(and_, (K - a - b <= 0 for (a, b) in zip(A, B)))
	print('YES' if w else 'NO')
T = int(raw_input())
for i in range(T):
	test_case()


def doCalc(a, b, n, k):
	res = 'YES'
	a.sort()
	b.sort()
	b.reverse()
	for i in range(n):
		if a[i] + b[i] < k:
			res = 'NO'
			break
	return res
for i in range(int(input())):
	(N, K) = (int(l) for l in input().split())
	A = [int(l) for l in input().split()]
	B = [int(l) for l in input().split()]
	print(doCalc(A, B, N, K))


import sys
numberOfCases = int(sys.stdin.readline())
Ns = []
Ks = []
As = []
Bs = []
for index in range(numberOfCases):
	raw = sys.stdin.readline().split()
	Ns.append(int(raw[0]))
	Ks.append(int(raw[1]))
	A = sys.stdin.readline().split()
	temp = []
	for index2 in range(Ns[index]):
		temp.append(int(A[index2]))
	temp.sort()
	As.append(temp)
	B = sys.stdin.readline().split()
	temp = []
	for index2 in range(Ns[index]):
		temp.append(int(B[index2]))
	temp.sort(reverse=True)
	Bs.append(temp)
for case in range(numberOfCases):
	try:
		for index in range(Ns[case]):
			if As[case][index] + Bs[case][index] < Ks[case]:
				raise ValueError('Ai+Bi != K')
		print('YES')
	except ValueError:
		print('NO')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = sorted(map(int, input().split()))
	b = sorted(map(int, input().split()))
	print('YES' if all((a[i] + b[n - i - 1] >= k for i in range(n))) else 'NO')


def ArraySumK(ArrayA, ArrayB, k):
	for i in range(len(ArrayB)):
		if ArrayA[i] + ArrayB[i] >= k:
			continue
		else:
			return 'NO'
	return 'YES'
noTestCases = input()
for i in range(int(noTestCases)):
	line = input().split(' ')
	N = int(line[0])
	K = int(line[1])
	ArrayA = [int(i) for i in input().split(' ')]
	ArrayB = [int(i) for i in input().split(' ')]
	ArrayA.sort()
	ArrayB.sort(reverse=True)
	print(ArraySumK(ArrayA, ArrayB, K))


T = int(input())
for case in range(T):
	(n, K) = map(int, input().split())
	A = sorted(map(int, input().split()))
	B = sorted(map(int, input().split()), reverse=True)
	if all(map(lambda t: sum(t) >= K, zip(A, B))):
		print('YES')
	else:
		print('NO')


m = input()
a = int(m)
x = 1
while x <= a:
	res = 'NO'
	l = input()
	klm = int(l.split(' ')[1])
	mj = input()
	fa = mj.split(' ')
	mk = input()
	fb = mk.split(' ')
	A = []
	B = []
	for k in range(len(fa)):
		A.append(int(fa[k]))
		B.append(int(fb[k]))
	A.sort()
	B.sort(reverse=True)
	for i in range(len(A)):
		if A[i] + B[i] >= klm:
			res = 'YES'
		else:
			res = 'NO'
			break
	print(res)
	x += 1


def read_int():
	return int(input().strip())

def read_int_list():
	return list(map(int, input().strip().split()))
T = read_int()
for i in range(T):
	(N, K) = read_int_list()
	A = sorted(read_int_list())
	B = reversed(sorted(read_int_list()))
	sums = (a + b for (a, b) in zip(A, B))
	if all((s >= K for s in sums)):
		print('YES')
	else:
		print('NO')


T = int(input())
for t in range(T):
	(N, K) = list(map(int, str(input()).split()))
	A = list(map(int, str(input()).split()))
	B = list(map(int, str(input()).split()))
	A.sort()
	B.sort()
	B.reverse()
	exists = True
	for i in range(N):
		if A[i] + B[i] < K:
			exists = False
			break
	if exists:
		print('YES')
	else:
		print('NO')


T = int(input())
for t in range(0, T):
	(N, K) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a.sort()
	b.sort(reverse=True)
	ans = 'YES'
	for j in range(0, N):
		if a[j] + b[j] < K:
			ans = 'NO'
			break
	print(ans)


import sys
import collections
t = int(input())

def twoarrays(A, B):
	A.sort()
	B.sort(reverse=True)
	for i in range(len(A)):
		if A[i] + B[i] < k:
			print('NO')
			return
	print('YES')
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	twoarrays(A, B)


T = int(input())
for t in range(T):
	(N, K) = [int(v) for v in input().split()]
	A = sorted([int(v) for v in input().split()])
	B = sorted([int(v) for v in input().split()], reverse=True)
	result = 'YES'
	for i in range(N):
		if A[i] + B[i] < K:
			result = 'NO'
			break
	print(result)


numTests = int(input())
assert 1 <= numTests <= 10
for _ in range(numTests):
	(howMany, maxValue) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	assert 1 <= howMany <= 1000
	assert 1 <= maxValue <= 10 ** 9
	assert len(A) == howMany and len(B) == howMany
	A.sort()
	B.sort(reverse=True)
	conditionMet = 'YES'
	for e in range(len(A)):
		if A[e] + B[e] < maxValue:
			conditionMet = 'NO'
	print(conditionMet)


f = lambda : list(map(int, input().strip().split(' ')))
n = f()[0]
for _ in range(n):
	(n, k) = f()
	a = sorted(f())
	b = sorted(f(), reverse=True)
	for i in range(n):
		if a[i] + b[i] < k:
			print('NO')
			break
	else:
		print('YES')


T = int(input())
for t in range(T):
	(N, K) = tuple((int(s) for s in input().split()))
	A = tuple((int(s) for s in input().split()))
	B = tuple((int(s) for s in input().split()))
	A = sorted(A)
	B = sorted(B, reverse=True)
	r = True
	for p in range(N):
		if A[p] + B[p] < K:
			r = False
			break
	print('YES' if r else 'NO')


for t in range(int(input())):
	(_, K) = (int(i) for i in input().split())
	ar1 = sorted([int(i) for i in input().split()])
	ar2 = sorted([int(i) for i in input().split()], reverse=True)
	for (a, b) in zip(ar1, ar2):
		if a + b < K:
			print('NO')
			break
	else:
		print('YES')


T = int(input())
for t in range(T):
	(N, K) = [int(e) for e in input().split()]
	A = [int(e) for e in input().split()]
	B = [int(e) for e in input().split()]
	A.sort()
	B.sort()
	B.reverse()
	if all([a + b >= K for (a, b) in zip(A, B)]):
		print('YES')
	else:
		print('NO')


T = int(input())
for i in range(T):
	flag = True
	(n, k) = input().split()
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	arr1 = sorted(arr1)
	arr2 = sorted(arr2, reverse=True)
	for j in range(int(n)):
		if arr1[j] + arr2[j] < int(k):
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


import sys
T = int(sys.stdin.readline().strip())
while T > 0:
	(N, K) = [int(x) for x in sys.stdin.readline().split()]
	A = sorted([int(x) for x in sys.stdin.readline().split()])
	B = sorted([int(x) for x in sys.stdin.readline().split()], reverse=True)
	results = [A[i] + B[i] >= K for i in range(len(A))]
	result = 'NO' if sum(results) < len(A) else 'YES'
	print(result)
	T -= 1


T = int(input())
for t in range(T):
	[N, K] = [int(e) for e in input().split()]
	A = sorted([int(e) - K for e in input().split()])
	B = sorted([int(e) for e in input().split()])
	count_B = {}.fromkeys(set(B), 0)
	for b in B:
		count_B[b] += 1
	ok = True
	for a in A:
		found = False
		for b in B:
			if count_B[b] > 0 and a + b >= 0:
				count_B[b] -= 1
				found = True
				break
		if not found:
			print('NO')
			ok = False
			break
	if ok:
		print('YES')


def get_and_return_list():
	return list(map(lambda x: int(x), input().split(' ')))

def check_can(k, list1, list2):
	list1.sort()
	list2.sort()
	for i in list1:
		for j in range(len(list2)):
			if i + list2[j] >= k:
				list2.pop(j)
				break
	if len(list2) == 0:
		print('YES')
	else:
		print('NO')
n = int(input())
for i in range(n):
	(n, k) = get_and_return_list()
	list1 = get_and_return_list()
	list2 = get_and_return_list()
	check_can(k, list1, list2)


tests = int(input())
for t in range(tests):
	(N, K) = (int(x) for x in input().split())
	aArr = [int(x) for x in input().split()]
	bArr = [int(x) for x in input().split()]
	aArr.sort()
	bArr.sort(reverse=True)
	shouldAnswer = True
	for i in range(N):
		if aArr[i] + bArr[i] < K:
			shouldAnswer = False
			print('NO')
			break
	if shouldAnswer:
		print('YES')


cases = int(input())
for _ in range(cases):
	(N, K) = str(input()).split()
	array_length = int(N)
	required_sum = int(K)
	one = sorted([int(s) for s in str(input()).split()])
	two = sorted([int(t) for t in str(input()).split()])
	good_enough = 'YES'
	for i in range(len(one)):
		if one[i] + two[len(two) - i - 1] < required_sum:
			good_enough = 'NO'
	print(good_enough)


def check_arrays(A, B):
	for (item1, item2) in zip(A, B):
		if item1 + item2 < K:
			return 'NO'
	return 'YES'
num_cases = int(input())
for i in range(num_cases):
	(N, K) = input().split()
	N = int(N)
	K = int(K)
	A = input().split()
	B = input().split()
	A = [int(item) for item in A]
	B = [int(item) for item in B]
	A.sort()
	B.sort()
	B.reverse()
	print(check_arrays(A, B))


for i in range(int(input())):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	A.sort()
	B.sort(reverse=True)
	for i in range(N):
		if A[i] + B[i] < K:
			print('NO')
			break
		else:
			pass
	else:
		print('YES')


def tst1(A, B, k):
	A.sort()
	B.sort()
	for i in range(len(A)):
		if A[i] + B[-i - 1] < k:
			return False
	return True
T = int(input())
res = []
for i in range(T):
	(N, K) = (int(i) for i in input().split())
	A = [int(i) for i in input().split()]
	B = [int(i) for i in input().split()]
	if tst1(A, B, K) == True:
		res.append('YES')
	else:
		res.append('NO')
for i in res:
	print(i)


import fileinput

def exists_perm(list1, list2, k):
	l1_sorted = sorted(list1, reverse=True)
	l2_sorted = sorted(list2)
	for (ai, bi) in zip(l1_sorted, l2_sorted):
		if ai + bi < k:
			return False
	return True

def to_int_list(list):
	return [int(e) for e in list]
input = []
for line in fileinput.input():
	input.append(line)
(test_nmbr, test_input) = (int(input[0]), input[1:])
for t in range(test_nmbr):
	(_, k) = to_int_list(test_input[t * 3].split(' '))
	list_a = to_int_list(test_input[t * 3 + 1].split(' '))
	list_b = to_int_list(test_input[t * 3 + 2].split(' '))
	if exists_perm(list_a, list_b, k):
		print('YES')
	else:
		print('NO')


def func():
	(n, k) = map(int, input().split())
	la = list(map(int, input().split()))
	lb = list(map(int, input().split()))
	la.sort(reverse=False)
	lb.sort(reverse=True)
	for i in range(n):
		if la[i] + lb[i] < k:
			return False
	return True
n = int(input())
for i in range(n):
	if func():
		print('YES')
	else:
		print('NO')


cases = []
T = int(input())
for i in range(T):
	(N, K) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	cases.append([K, a, b])

def sums_k(k, a, b):
	a = sorted(a)
	b = sorted(b, reverse=True)
	for c in map(lambda x, y: x + y, a, b):
		if c < k:
			return False
	return True
for case in cases:
	print('YES' if sums_k(*case) else 'NO')


T = int(input())
for i in range(T):
	(N, K) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a = sorted(a)
	b = sorted(b, reverse=True)
	c = [a[i] + b[i] for i in range(N)]
	if min(c) < K:
		print('NO')
	else:
		print('YES')


def check_lists(k, a, b):
	a = sorted(a)
	b = sorted(b, reverse=True)
	return all((ai + bi >= k for (ai, bi) in zip(a, b)))

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

def main():
	num_tests = int(input())
	for i in range(num_tests):
		(n, k) = parse_line(input())
		a = parse_line(input())
		b = parse_line(input())
		if check_lists(k, a, b):
			print('YES')
		else:
			print('NO')
main()


cases = int(input())
for _ in range(cases):
	(array_size, k) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	a.sort()
	b.sort()
	b.reverse()
	lt = [True for (x, y) in zip(a, b) if x + y < k]
	if lt:
		print('NO')
	else:
		print('YES')


T = int(input())

def findOrdering(A, B, K, N):
	A.sort()
	B.sort()
	B.reverse()
	for i in range(N):
		if A[i] + B[i] < K:
			return 'NO'
	return 'YES'
for _ in range(T):
	(N, K) = [int(token) for token in input().split(' ')]
	A = [int(token) for token in input().split(' ')]
	B = [int(token) for token in input().split(' ')]
	print(findOrdering(A, B, K, N))


def check(array1, array2, num):
	for (i, j) in zip(array1, array2):
		if i + j < num:
			return 'NO'
	return 'YES'
cases = int(input())
for i in range(cases):
	(length, num) = map(int, input().split())
	array1 = sorted(list(map(int, input().split())))
	array2 = sorted(list(map(int, input().split())))
	array2.reverse()
	ans = check(array1, array2, num)
	print(ans)


def greatest_less_or_equal(key, array):
	for x in sorted(array):
		if x >= key:
			return x
	return False

def two_arrays(list_a, list_b, k, n):
	(list_a, list_b) = (sorted(list_a), sorted(list_b)[::-1])
	for index in range(n):
		if list_a[index] + list_b[index] < k:
			return False
	return True
for case in range(int(input())):
	(n, k) = [int(x) for x in input().split(' ')]
	list_a = [int(x) for x in input().split(' ')]
	list_b = [int(x) for x in input().split(' ')]
	if two_arrays(list_a, list_b, k, n):
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(n, k) = [int(e) for e in input().split(' ')]
	a = [int(e) for e in input().split(' ')]
	b = sorted([int(e) for e in input().split(' ')])
	for ea in a:
		for eb in b:
			if ea + eb >= k:
				b.remove(eb)
				break
		else:
			print('NO')
			break
	else:
		print('YES')


testCases = int(input())
for i in range(testCases):
	(listLen, eqGtSum) = list(map(int, input().split(' ')))
	firstList = list(map(int, input().split(' ')))
	secondList = list(map(int, input().split(' ')))
	firstList.sort(key=lambda x: -x)
	secondList.sort(key=lambda x: x)
	flag = True
	for index in range(len(firstList)):
		if firstList[index] + secondList[index] < eqGtSum:
			print('NO')
			flag = False
			break
	if flag:
		print('YES')


for _ in range(int(input())):
	(N, K) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l1.sort()
	l2 = sorted(l2)[::-1]
	ok = min([l1[i] + l2[i] for i in range(len(l1))]) >= K
	if ok:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	array1 = sorted([int(i) for i in input().split()])
	array2 = sorted([int(i) for i in input().split()])[::-1]
	res = True
	for (a, b) in zip(array1, array2):
		if a + b < k:
			res = False
	if res == True:
		print('YES')
	else:
		print('NO')


from sys import stdin

def is_summable(A, B, k):
	for (a, b) in zip(sorted(A), sorted(B, reverse=True)):
		if a + b < k:
			return False
	return True
T = int(stdin.readline())
for t in range(T):
	(n, k) = [int(x) for x in stdin.readline().split()]
	A = [int(x) for x in stdin.readline().split()]
	B = [int(x) for x in stdin.readline().split()]
	print('YES' if is_summable(A, B, k) else 'NO')


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


def check(a, b):
	a.sort()
	b.sort(reverse=True)
	for i in range(n):
		if a[i] + b[i] < k:
			print('NO')
			return
	print('YES')
c = int(input())
for i in range(c):
	(n, k) = [int(x) for x in input().strip().split()]
	a = [int(x) for x in input().strip().split()]
	b = [int(x) for x in input().strip().split()]
	assert n == len(a) == len(b)
	check(a, b)


def main():

	def makelistsameline(strnos):
		return list(map(int, strnos.split()))
	T = int(input())
	for x in range(T):
		(N, K) = makelistsameline(input())
		a = makelistsameline(input())
		b = makelistsameline(input())
		if check(a, b, K) == True:
			print('YES')
		else:
			print('NO')

def check(l1, l2, k):
	l1.sort()
	l2.sort(reverse=True)
	for (a, b) in zip(l1, l2):
		if a + b < k:
			return False
	return True
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	b = sorted(list(map(int, input().split())))[::-1]
	res = 'YES'
	for i in range(n):
		if a[i] + b[i] < k:
			res = 'NO'
	print(res)


T = int(input())
for z in range(T):
	(N, K) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	A.sort()
	B.sort(reverse=True)
	for i in range(N):
		if A[i] + B[i] < K:
			print('NO')
			break
	else:
		print('YES')


def compute(array1, array2, k):
	array1.sort()
	array2.sort()
	array2.reverse()
	for x in range(len(array1)):
		if array1[x] + array2[x] < k:
			return False
	return True
tcs = int(input())
for tc in range(tcs):
	inpt = input().split(' ')
	k = int(inpt[1])
	arr1 = input().split(' ')
	arr2 = [int(elem) for elem in arr1]
	arr3 = input().split(' ')
	arr4 = [int(elem) for elem in arr3]
	if compute(arr2, arr4, k):
		print('YES')
	else:
		print('NO')


def rl(T=str):
	return list(map(T, input().split()))
(T,) = rl(int)
for _ in range(T):
	(N, K) = rl(int)
	A = rl(int)
	B = rl(int)
	A.sort()
	B.sort(reverse=True)
	bad = len([a + b for (a, b) in zip(A, B) if a + b < K]) > 0
	print('NO' if bad else 'YES')


cases = int(input())

def test(n, k, a_array, b_array):
	for x in range(n):
		if a_array[x] + b_array[x] < k:
			return 'NO'
	return 'YES'
for i in range(cases):
	(n, k) = [int(j) for j in str(input()).split()]
	a_array = [int(j) for j in str(input()).split()]
	b_array = [int(j) for j in str(input()).split()]
	a_array.sort()
	b_array.sort(reverse=True)
	print(test(n, k, a_array, b_array))


def existeix(a, b, suma):
	a.sort()
	b.sort()
	b.reverse()
	existeix = True
	i = 0
	for ai in a:
		if ai + b[i] < suma:
			print('NO')
			existeix = False
			break
		i = i + 1
	if existeix:
		print('YES')
lines = int(input())
l = 0
while l < lines:
	first = input().split()
	posicions = int(first[0])
	suma = int(first[1])
	i = 0
	taula = input().split()
	taula2 = input().split()
	taula = list(map(int, taula))
	taula2 = list(map(int, taula2))
	existeix(taula, taula2, suma)
	l = l + 1