Rachel has a date and tells everyone she is not mad at Ross but doesn't have any feelings for him anymore either. Seeing her date for the first time, everyone notices that he looks exactly like Ross. However, Rachel refuses to believe so.

Rachel makes a list of N characteristics and assigns a score to both Ross and Russ for each of the characteristics. Ross' i^{th} characteristic has a score equal to A_{i} and Russ' i^{th} characteristic has a score equal to B_{i}. Rachel decides that Russ looks exactly like Ross if the following condition is satisfied for at least X distinct values of j, 1 ≤ j ≤ N :

|A_{j} - B_{j}| ≤ K.  

Help Rachel in finding if both are alike.

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

- First line will contain T, number of testcases. Then the testcases follow.
- First line for each test case contains three integers N, X and K, denoting the number of characteristics, the minimum number of characteristics  and maximum possible score difference.
- Second line for each test case contains N integers denoting array A.
- Third line for each test case contains N integers denoting array B.

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

For each test case print "YES" if they are alike, else print "NO".

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

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

$1 ≤ T ≤ 10$
$1 ≤ N ≤ 10^{3}$
$1 ≤ A_{i}, B_{i} ≤ 10^{3}$
$1 ≤ X ≤ n$
$0 ≤ K ≤ 10^{3}$

----- Sample Input 1 ------ 
3
4 2 2
1 7 7 5
1 8 1 2
5 1 3
9 8 7 2 5
5 4 1 8 9
3 3 0
2 3 4
2 3 4

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

----- explanation 1 ------ 
Test case 1: The values of absolute difference between scores of Ross' and Russ' characteristics $1$ and $2$ are $0$ and $1$ respectively, both these values are less than $K = 2$. Thus, Ross and Russ are alike.

Test case 2: The values of absolute difference between the scores of *ALL* of the Ross' and Russ' characteristics are greater than $3$.

Source: codechef | Difficulty: EASY
Tags: Mathematics

Implementation

Complete search


Solutions:
for _ in range(int(input())):
	(n, x, k) = map(int, input().split())
	li = list(map(int, input().split()))
	li2 = list(map(int, input().split()))
	c = 0
	for i in range(n):
		if abs(li[i] - li2[i]) <= k:
			c += 1
	if c >= x:
		print('YES')
	else:
		print('NO')


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


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


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	co = 0
	for j in range(a):
		if abs(l[j] - m[j]) < c:
			co += 1
	if co >= b or c == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(N, X, K) = map(int, input().split())
	ross = list(map(int, input().split()))
	russ = list(map(int, input().split()))
	c = 0
	for i in range(N):
		if abs(ross[i] - russ[i]) <= K:
			c += 1
	if c >= X:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(N, X, K) = map(int, input().split())
	L1 = list(map(int, input().split()))
	L2 = list(map(int, input().split()))
	flag = 0
	c = 0
	for i in range(N):
		if abs(L1[i] - L2[i]) <= K:
			c += 1
			if c == X:
				flag = 1
				break
	if flag:
		print('YES')
	else:
		print('NO')


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


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, x, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	v = 0
	for i in range(n):
		v += 1 if abs(a[i] - b[i]) <= k else 0
	print('YES' if v >= x else 'NO')


t = int(input())
for i in range(t):
	(n, x, k) = map(int, input().split(' '))
	ele = list(map(int, input().split()))
	ala = list(map(int, input().split()))
	count = 0
	for j in range(0, n):
		if ele[j] - ala[j] <= k and ele[j] - ala[j] >= -k:
			count = count + 1
	if count >= x:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(N, X, K) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	count = 0
	for i in range(N):
		if abs(A[i] - B[i]) <= K:
			count = count + 1
	if count >= X:
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	(n, x, k) = map(int, input().split())
	a = list(map(int, input().strip().split()))[:n]
	b = list(map(int, input().strip().split()))[:n]
	similar = 0
	for num in range(n):
		if abs(a[num] - b[num]) <= k:
			similar += 1
	if similar >= x:
		print('YES')
	else:
		print('NO')


def lookAlike(A, B):
	count = 0
	for i in range(len(A)):
		if B[i] - K <= A[i] <= B[i] + K:
			count += 1
		if count == X:
			return 'YES'
	return 'NO'
for _ in range(int(input())):
	(N, X, K) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	print(lookAlike(A, B))


t = int(input())
for i in range(t):
	n_x_k = input().split(' ')
	ross = input().split(' ')
	russ = input().split(' ')
	char_count = 0
	for j in range(int(n_x_k[0])):
		if abs(int(ross[j]) - int(russ[j])) <= int(n_x_k[2]):
			char_count += 1
		if char_count >= int(n_x_k[1]):
			print('YES')
			break
	else:
		print('NO')


t = int(input())
for tc in range(t):
	(n, x, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	d = []
	f = []
	for j in range(n):
		c = abs(a[j] - b[j])
		d.append(c)
	for j in d:
		if j <= k:
			f.append(j)
	if len(f) >= x:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, x, k) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	re = 0
	for (a, b) in zip(l1, l2):
		if abs(a - b) <= k:
			re += 1
		if re >= x:
			print('YES')
			break
	else:
		print('NO')


t = int(input())
for i in range(t):
	(n, x, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	d = 0
	for i in range(n):
		c.append(abs(a[i] - b[i]))
	for j in c:
		if j <= k:
			d += 1
		else:
			d += 0
	if d >= x:
		print('YES')
	else:
		print('NO')


x = int(input())
pp = []
for jd in range(0, x):
	df = str(input())
	oi = df.split(' ')
	tbvc = str(input())
	uumn = str(input())
	hnvc = []
	for iiu in tbvc.split(' '):
		hnvc.append(int(iiu))
	jawe = []
	for rr in uumn.split(' '):
		jawe.append(int(rr))
	mfgt = []
	for ee in oi:
		mfgt.append(int(ee))
	jvcx = [mfgt, hnvc, jawe]
	pp.append(jvcx)
for nnc in pp:
	opg = nnc[0]
	kty = nnc[1]
	prt = nnc[2]
	e = 0
	for ii in range(0, len(kty)):
		gg = kty[ii] - prt[ii]
		if gg < 0:
			gg *= -1
		if gg <= opg[2]:
			e += 1
	if e >= opg[1]:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	l = list(map(int, input().split()))
	t = list(map(int, input().split()))
	h = 0
	for j in range(a):
		if abs(l[j] - t[j]) <= c:
			h += 1
		else:
			h += 0
	if h >= b:
		print('YES')
	else:
		print('NO')


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


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


t = int(input())
for i in range(t):
	(n, x, k) = map(int, input().split())
	l = [int(j) for j in input().split()]
	m = [int(j) for j in input().split()]
	c = 0
	for j in range(n):
		d = abs(l[j] - m[j])
		if d <= k:
			c = c + 1
	if c >= x:
		print('YES')
	else:
		print('NO')


for tc in range(int(input())):
	(n, x, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	count = 0
	for j in range(n):
		if abs(a[j] - b[j]) <= k:
			count += 1
	if count >= x:
		print('YES')
	else:
		print('NO')


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


for _ in range(int(input())):
	(n, x, k) = map(int, input().split())
	arr = map(int, input().split())
	arr1 = map(int, input().split())
	l = []
	for (i, j) in zip(arr, arr1):
		if abs(i - j) <= k:
			l.append(abs(i - j))
	if len(l) >= x:
		print('YES')
	else:
		print('NO')


from math import sqrt, ceil, floor, gcd, log2
import sys
from sys import stdin, stdout
from collections import Counter, defaultdict, OrderedDict, deque
from itertools import combinations, groupby
from time import time
from heapq import heappop, heappush, heapify
t = int(input())
for _ in range(t):
	(n, x, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	cnt = 0
	for i in range(n):
		if abs(a[i] - b[i]) <= k:
			cnt += 1
	if cnt >= x:
		print('YES')
	else:
		print('NO')


T = int(input())
while T:
	T -= 1
	(N, X, K) = list(map(int, input().split(' ')))
	A = list(map(int, input().split(' ')))
	B = list(map(int, input().split(' ')))
	Diff = [abs(x - y) for (x, y) in zip(A, B)]
	D_K = []
	for i in Diff:
		if i <= K:
			D_K.append(i)
		else:
			continue
	if len(D_K) >= X:
		print('YES')
	else:
		print('NO')


def main():
	T = int(input())
	for _ in range(T):
		(N, X, K) = map(int, input().split())
		A = list(map(int, input().split(' ')))[:N]
		B = list(map(int, input().split(' ')))[:N]
		for i in range(N):
			if abs(A[i] - B[i]) <= K:
				X -= 1
			if X == 0:
				print('YES')
				break
		else:
			print('NO')
main()


t = int(input())
for t in range(t):
	(n, x, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	count = 0
	for j in range(n):
		if abs(a[j] - b[j]) <= k:
			count += 1
			if count >= x:
				print('YES')
				break
			else:
				continue
	if count < x:
		print('NO')


for t in range(int(input())):
	(x, k) = [int(i) for i in input().split()][1:]
	ai = [int(i) for i in input().split()]
	bi = [int(i) for i in input().split()]
	for i in range(len(ai)):
		if abs(ai[i] - bi[i]) <= k:
			x -= 1
	if x <= 0:
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	t = t - 1
	(n, x, k) = input().split(' ')
	n = int(n)
	x = int(x)
	k = int(k)

	def rec_sim(char1, char2, start, end, k):
		if start == end:
			if abs(int(char1[start]) - int(char2[start])) <= k:
				x = 1
				return x
			else:
				x = 0
				return x
		mid = int((start + end) // 2)
		left_Score = rec_sim(char1, char2, start, mid, k)
		right_score = rec_sim(char1, char2, mid + 1, end, k)
		return left_Score + right_score
	ross_char = input().split(' ')
	russ_char = input().split(' ')
	score = rec_sim(ross_char, russ_char, 0, n - 1, k)
	if score >= x:
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	t = t - 1
	(n, x, k) = input().split(' ')
	n = int(n)
	x = int(x)
	k = int(k)
	ross_char = input().split(' ')
	russ_char = input().split(' ')
	for i in range(int(n)):
		if abs(int(ross_char[i]) - int(russ_char[i])) <= int(k):
			x = x - 1
			if x == 0:
				print('YES')
				break
	if x != 0:
		print('NO')


for _ in range(int(input())):
	(n, x, k) = map(int, input().split())
	lsta = [int(x) for x in input().split()]
	lstb = [int(x) for x in input().split()]
	coun = 0
	for (i, j) in enumerate(lsta):
		if abs(j - lstb[i]) <= k:
			coun += 1
	if coun >= x:
		print('YES')
	else:
		print('NO')