A sequence of $n$ numbers is called a permutation if it contains all integers from $1$ to $n$ exactly once. For example, the sequences [$3, 1, 4, 2$], [$1$] and [$2,1$] are permutations, but [$1,2,1$], [$0,1$] and [$1,3,4$] — are not.

Polycarp lost his favorite permutation and found only some of its elements — the numbers $b_1, b_2, \dots b_m$. He is sure that the sum of the lost elements equals $s$.

Determine whether one or more numbers can be appended to the given sequence $b_1, b_2, \dots b_m$ such that the sum of the added numbers equals $s$, and the resulting new array is a permutation?


-----Input-----

The first line of input contains a single integer $t$ ($1 \le t \le 100$) —the number of test cases.

Then the descriptions of the test cases follow.

The first line of each test set contains two integers $m$ and $s$ ($1 \le m \le 50$, $1 \le s \le 1000$)—-the number of found elements and the sum of forgotten numbers.

The second line of each test set contains $m$ different integers $b_1, b_2 \dots b_m$ ($1 \le b_i \le 50$) — the elements Polycarp managed to find.


-----Output-----

Print $t$ lines, each of which is the answer to the corresponding test set. Print as the answer YES if you can append several elements to the array $b$, that their sum equals $s$ and the result will be a permutation. Output NO otherwise.

You can output the answer in any case (for example, yEs, yes, Yes and YES will be recognized as positive answer).


-----Examples-----

Input
5
3 13
3 1 4
1 1
1
3 3
1 4 2
2 1
4 3
5 6
1 2 3 4 5
Output
YES
NO
YES
NO
YES


-----Note-----

In the test case of the example, $m=3, s=13, b=[3,1,4]$. You can append to $b$ the numbers $6,2,5$, the sum of which is $6+2+5=13$. Note that the final array will become $[3,1,4,6,2,5]$, which is a permutation.

In the second test case of the example, $m=1, s=1, b=[1]$. You cannot append one or more numbers to $[1]$ such that their sum equals $1$ and the result is a permutation.

In the third test case of the example, $m=3, s=3, b=[1,4,2]$. You can append the number $3$ to $b$. Note that the resulting array will be $[1,4,2,3]$, which is a permutation.

Difficulty: EASY
Tags: Mathematics

Starter code:

Solutions:
import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
test_cases = inp()
inp_arr = []
for i in range(test_cases):
	l1 = inlt()
	l2 = inlt()
	inp_arr.append((l1[1], l2))

def findResult(s, nums):
	exist_nums = {}
	for num in nums:
		exist_nums[num] = True
	lost_nums = []
	m = max(list(exist_nums.keys()))
	for i in range(1, m + 1):
		if i not in exist_nums:
			lost_nums.append(i)
	while len(lost_nums) > 0:
		s -= lost_nums.pop()
		if s < 0:
			return 'NO'
	if s == 0:
		return 'YES'
	while s > 0:
		s -= m + 1
		m += 1
		if s == 0:
			return 'YES'
		if s < 0:
			return 'NO'
	return 'YES'
result = [findResult(s, nums) for (s, nums) in inp_arr]
for m in result:
	print(m)


t = int(input())
for _ in range(t):
	(m, s) = map(int, input().split())
	arr = list(map(int, input().split()))
	arrset = set(arr)
	b = max(arr)
	for i in range(1, b + 1):
		if i not in arrset:
			s -= i
	if s < 0 or len(arrset) < len(arr):
		print('NO')
		continue
	k = b + 1
	while s > 0:
		s -= k
		k += 1
	print('YES' if s == 0 else 'NO')


for _ in range(int(input())):
	(m, s) = list(map(int, input().split()))
	nums = list(map(int, input().split()))
	for i in range(1, 1000):
		if i in nums:
			continue
		elif s - i == 0:
			nums.append(i)
			if len(nums) == max(nums):
				print('YES')
				break
			else:
				print('NO')
				break
		elif s - i > 0:
			s -= i
			nums.append(i)
		elif s - i < 0:
			print('NO')
			break


t = int(input())
for _ in range(t):
	(m, s) = map(int, input().split())
	a = list(map(int, input().split()))
	s += sum(a)
	sm = 0
	res = 0
	for i in range(1, s + 1):
		sm += i
		res = i
		if sm >= s:
			break
	if sm != s or max(a) > res:
		print('NO')
	else:
		print('YES')


n = int(input())
for i in range(n):
	(m, s) = str(input()).split()
	(m, s) = (int(m), int(s))
	mn = str(input()).split()
	mn = [int(a) for a in mn]
	mn = sorted(mn)
	sm = (2 * 1 + (max(mn) - 1)) / 2 * max(mn)
	s -= sm - sum(mn)
	b = max(mn)
	while s > 0:
		b += 1
		s -= b
	if s == 0:
		print('YES')
	else:
		print('NO')


def solve(n, s, p):
	_sum = sum(p)
	for i in range(1, 1000):
		k = i / 2 * (2 + (i - 1))
		if k == _sum + s and i >= max(p):
			return 'YES'
		elif k > _sum + s:
			return 'NO'
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	p = [int(x) for x in input().split()]
	print(solve(n, s, p))


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	for i in range(max(a), 101):
		if i * (i + 1) // 2 - s == y:
			print('YES')
			break
	else:
		print('NO')


t = int(input())
g = 'Yes' * 18
for i in range(t):
	(m, s) = map(int, input().split())
	r = set(map(int, input().split()))
	j = 1
	while s > 0:
		if j not in r:
			r.add(j)
			s -= j
		j += 1
	if s == 0 and max(r) == len(r):
		print('YES')
	else:
		print('NO')


def permute(m, s, a):
	ub = max(a)
	sum_ = 0
	for i in range(1, ub):
		if not i in a:
			sum_ += i
	if sum_ > s:
		return 'NO'
	elif sum_ == s:
		return 'YES'
	else:
		tmp_sum = sum_
		for i in range(ub + 1, 101):
			tmp_sum += i
			if tmp_sum == s:
				return 'YES'
			elif tmp_sum > s:
				return 'NO'
		return 'NO'
t = int(input())
for i in range(1, t * 2, 2):
	(m, s) = map(int, input().split())
	a = list(map(int, input().strip().split()))
	lt = []
	if m == 14 and s == 46:
		print(m, s)
		print(a)
	else:
		print(permute(m, s, a))


for _ in range(int(input())):
	(m, s) = map(int, input().split())
	l = list(map(int, input().split()))
	b = max(l)
	p = 0
	for i in range(1, b):
		if i not in l:
			p += i
	if p > s:
		print('NO')
	else:
		while True:
			if p == s:
				print('YES')
				break
			b += 1
			p += b
			if p > s:
				print('NO')
				break


t = int(input())
for i in range(t):
	(m, sum) = [int(x) for x in input().split()]
	s = input()
	arr = s.split()
	for i in range(m):
		arr[i] = int(arr[i])
	arr.sort()
	l = arr[m - 1]
	y = 0
	yy = 0
	for i in range(1, l + 1):
		if i not in arr:
			yy = yy + 1
	tuki = 0
	for i in range(1, l + 1):
		if i not in arr:
			sum = sum - i
			tuki = tuki + 1
			if sum < 0 and tuki == yy:
				print('NO')
				y = 1
				break
			elif sum < 0 and tuki != yy:
				y = 1
				print('NO')
				break
			elif sum == 0 and tuki != yy:
				y = 1
				print('NO')
				break
			elif sum == 0 and tuki == yy:
				y = 1
				print('YES')
				break
	if y == 0:
		for j in range(l + 1, 2000):
			sum = sum - j
			if sum < 0:
				print('NO')
				break
			elif sum == 0:
				print('YES')
				break


buf = list()
t = int(input())
for i in range(t):
	(m, s) = map(int, input().split())
	st = set(map(int, input().split()))
	mx = max(st)
	base = 0
	for j in range(mx + 1):
		if j not in st:
			base += j
	while base < s:
		mx += 1
		base += mx
	if base == s:
		buf.append('YES')
	else:
		buf.append('NO')
for b in buf:
	print(b)


for _ in range(int(input())):
	(m, s) = map(int, input().split())
	a = sorted(map(int, input().split()))
	cnt = 0
	x = 1
	i = 0
	while i < m:
		if a[i] == x:
			i += 1
			x += 1
		else:
			cnt += x
			x += 1
	while cnt < s:
		cnt += x
		x += 1
	if cnt == s:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(m, s) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	mx = sum(a)
	x = 1
	while sum(a) - s < mx:
		if x not in a:
			a.append(x)
		x += 1
	print('YES' if sum(a) - s == mx and len(a) == max(a) else 'NO')


for _ in range(int(input())):
	(m, s) = map(int, input().split())
	b = list(map(int, input().split()))
	a = sum(b) + s
	flag = 0
	i = 0
	sum1 = 0
	while True:
		if sum1 == a:
			flag = 1
			break
		if sum1 > a:
			break
		i += 1
		sum1 += i
	if flag == 0:
		print('NO')
	elif max(b) > i:
		print('NO')
	else:
		print('YES')


t = int(input())
answers = []
for i in range(t):
	(m, s) = map(int, input().split())
	b = list(map(int, input().split()))
	k = 1
	s1 = 0
	while s1 < s:
		if k not in b:
			b.append(k)
			s1 += k
		k += 1
	b.sort()
	bol = True
	for j in range(1, len(b)):
		if b[j] - b[j - 1] != 1:
			bol = False
	if s1 == s and bol:
		answers.append('YES')
	else:
		answers.append('NO')
for i in answers:
	print(i)


for tst in range(int(input())):
	(m, sx) = map(int, input().split())
	a = list(map(int, input().split()))
	s = set(a)
	b = []
	for i in range(1, max(a)):
		if i not in s:
			b.append(i)
	su = sum(b)
	x = max(a) + 1
	while sum(b) < sx:
		b.append(x)
		x += 1
	print('YES' if sum(b) == sx else 'NO')


t = int(input())
for _ in range(t):
	ms = [int(ii) for ii in input().split()]
	(m, s) = (ms[0], ms[1])
	b = [int(iii) for iii in input().split()]
	bm = max(b)
	for i in range(1, bm):
		if i not in b:
			s -= i
	while s > 0:
		bm += 1
		s -= bm
	if s < 0:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	(m, s) = map(int, input().split())
	b = list(map(int, input().split()))
	b.sort()
	d = max(b)
	s -= d * (d + 1) // 2 - sum(b)
	if s == 0:
		print('YES')
	else:
		g = d + 1
		while s > 0:
			s -= g
			g += 1
		if s == 0:
			print('YES')
		else:
			print('NO')


t = int(input())
for i in range(t):
	(m, s) = map(int, input().split())
	b = list(map(int, input().split()))
	b = sorted(b)
	p = [0] * max(b)
	for v in b:
		p[v - 1] = v
	for z in range(len(p)):
		if p[z] == 0:
			s -= z + 1
			p[z] = z + 1
	w = max(p)
	if s > 0:
		while s > 0:
			w += 1
			s -= w
			p.append(w)
	if s < 0 or 0 in p:
		print('NO')
	else:
		print('YES')


def func(b, m, s):
	elemax = 0
	found = [0] * 101
	for x in b:
		found[x] = 1
		elemax = max(elemax, x)
	miss = 0
	for x in range(1, elemax):
		miss += x if found[x] == 0 else 0
	if miss > s:
		return False
	if miss == s:
		return True
	if miss < s:
		s -= miss
		elemax += 1
		while s > 0:
			s -= elemax
			elemax += 1
		return s == 0
T = int(input())
for _ in range(T):
	(m, s) = map(int, input().split(' '))
	b = [int(x) for x in list(input().split(' '))]
	print('YES' if func(b, m, s) else 'NO')


for _ in range(int(input())):
	(m, s) = map(int, input().split())
	l = list(map(int, input().split()))
	maxl = max(l)
	for i in range(maxl):
		if i not in l:
			s -= i
	maxl += 1
	while s > 0:
		s -= maxl
		maxl += 1
	if s == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
results = []
for i in range(t):
	a = list(map(int, input().strip().split()))
	(m, s) = (a[0], a[1])
	numbers = list(map(int, input().strip().split()))
	maximum = max(numbers)
	sum_of_num = sum(numbers)
	expected = maximum * (maximum + 1) // 2
	diff = expected - sum_of_num
	s -= diff
	curr = maximum + 1
	while True:
		if s == 0:
			results.append('YES')
			break
		elif s < 0:
			results.append('NO')
			break
		else:
			s -= curr
			curr += 1
for k in results:
	print(k)


def solve():
	(x, s) = map(int, input().split())
	l = list(map(int, input().split()))
	for i in range(1, s + 1):
		if s <= 0:
			break
		elif i not in l:
			s -= i
			l = l + [i]
	l.sort()
	if l[len(l) - 1] == len(l) and s == 0:
		return 'YES'
	else:
		return 'NO'
for __ in range(int(input())):
	print(solve())


for tc in range(int(input())):
	(n, s) = map(int, input().split())
	l = list(map(int, input().split()))
	m = max(l)
	ml = []
	for i in range(1, m + 1):
		if i not in l:
			ml.append(i)
	sml = sum(ml)
	s -= sml
	if s == 0:
		print('YES')
	else:
		m += 1
		while s > 0:
			s -= m
			m += 1
		if s == 0:
			print('YES')
		else:
			print('NO')


t = int(input())
while t > 0:
	t -= 1
	(m, s) = map(int, input().split())
	a = [int(x) for x in input().split()]
	sums = (sum(a) + s) * 2
	a = sorted(a)
	i = 1
	while i * (i + 1) < sums:
		i += 1
	if i * (i + 1) != sums:
		print('NO')
	else:
		p = 0
		for k in range(1, i + 1):
			if k not in a:
				p += k
		if p == s:
			print('YES')
		else:
			print('NO')


def lstRd() -> list:
	return list(map(int, input().split()))

def intRd():
	return int(input())

def lstStrRd():
	return list(input())
for _ in range(intRd()):
	(m, s) = lstRd()
	b = lstRd()
	fot = []
	for i in range(1, max(b)):
		if i not in b:
			fot.append(i)
	ss = sum(fot)
	if ss == s:
		print('YES')
	elif ss > s:
		print('NO')
	else:
		i = 1
		temp = max(b) + i
		while True:
			if ss + temp == s:
				print('YES')
				break
			elif ss + temp > s:
				print('NO')
				break
			i += 1
			temp += max(b) + i


for _ in range(int(input())):
	(m, s) = map(int, input().split())
	l = list(map(int, input().split()))
	q = max(l)
	w = 0
	s1 = sum(l)
	s2 = q * (q + 1) // 2
	k = s2 - s1
	if s > k:
		d = s - k
		i = q + 1
		while d > 0:
			d -= i
			i += 1
		if d == 0:
			print('YES')
		else:
			print('NO')
	elif s == k:
		print('YES')
	else:
		print('NO')


import math
import collections
for _ in range(int(input())):
	(m, s) = map(int, input().split())
	l = list(map(int, input().split()))
	sum = 0
	for k in l:
		sum += k
	d = collections.defaultdict(lambda : 0)
	flag = True
	total = s + sum
	newn = (math.sqrt(1 + 8 * total) - 1) / 2
	if math.floor(newn) == math.ceil(newn):
		ctr = 0
		for i in l:
			if d[i] == 0:
				d[i] += 1
			else:
				flag = False
				break
		if flag == False:
			print('NO')
			continue
		for q in range(1, int(newn) + 1):
			if d[q] == 0:
				ctr += 1
		if ctr + m == int(newn):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


for _ in range(0, int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	flag = True
	for i in range(1, 100):
		if not i in a:
			k -= i
		if k == 0 and i >= max(a):
			print('YES')
			flag = False
			break
	if flag:
		print('NO')


for _ in range(int(input())):
	(m, s) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = s + sum(a)
	per = 1
	i = 2
	while per < ans:
		per += i
		i += 1
	if per == ans and i > max(a):
		print('YES')
	else:
		print('NO')


t = int(input())

def solve(seq, m, s):
	a = max(seq)
	total = a * (a + 1) // 2
	total -= sum(seq)
	if total > s:
		return 'NO'
	elif total == s:
		return 'YES'
	else:
		for val in range(a + 1, s * 2):
			total += val
			if total > s:
				return 'NO'
				break
			elif total == s:
				return 'YES'
				break
		return 'NO'
for _ in range(t):
	(m, s) = [int(x) for x in input().split(' ')]
	seq = [int(x) for x in input().split(' ')]
	print(solve(seq, m, s))


t = int(input())
for T in range(t):
	(m, s) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	greater = max(arr)
	numbers = [False for x in range(greater + 1)]
	for it in arr:
		numbers[it] = True
	for i in range(1, len(numbers)):
		if not numbers[i]:
			s -= i
	while s > 0:
		greater += 1
		s -= greater
	if s == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
se = set()
for i in range(100):
	se.add(i * (i + 1) // 2)
for i in range(t):
	(m, s) = map(int, input().split())
	b = list(map(int, input().split()))
	a = max(b)
	mi = min(b)
	v = 1
	if a * (a + 1) // 2 > sum(b) + s:
		v = 0
	if sum(b) + s not in se:
		v = 0
	if mi < 1:
		v = 0
	if v:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(m, s) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	temp = 1
	sm = 0
	while sm < s:
		if temp not in arr:
			arr.append(temp)
			sm += temp
			temp += 1
		else:
			temp += 1
	if sm == s and len(arr) == max(arr):
		print('YES')
	else:
		print('NO')


d = {}
for i in range(1, 1000):
	d[int(i * (i + 1) // 2)] = i

def solve(arr, sm):
	for i in arr:
		if arr.count(i) > 1:
			print('NO')
			return
	if not sum(arr) + sm in d:
		print('NO')
		return
	temp = d[sm + sum(arr)]
	if max(arr) > temp:
		print('NO')
		return
	print('YES')
for _ in range(int(input())):
	(m, sm) = map(int, input().split())
	arr = list(map(int, input().split()))
	solve(arr, sm)


T = int(input())
for _ in range(T):
	(m, s) = map(int, input().split())
	l = list(map(int, input().split()))
	total = max(l) * (max(l) + 1) // 2
	if total > s + sum(l):
		print('NO')
		continue
	target = s - (total - sum(l))
	cum = max(l)
	while target > 0:
		cum += 1
		target -= cum
	if target == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(m, s) = map(int, input().split())
	a = list(map(int, input().split()))
	t = s + sum(a)
	cur = 0
	i = 0
	while cur < t:
		i += 1
		cur += i
	if i >= max(a) and cur == t:
		print('YES')
	else:
		print('NO')


from collections import Counter, defaultdict
import sys
import math

def sol(arr, m, s):
	k = sum(arr) + s
	val = (-1 + math.sqrt(1 + 8 * k)) / 2
	if int(val) != val:
		return 'NO'
	else:
		max_ = int(val)
		s = set()
		for i in range(len(arr)):
			if arr[i] in s or arr[i] > val:
				return 'NO'
			else:
				s.add(arr[i])
	return 'YES'
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	return str(input())

def invr():
	return map(int, input().split())
T = inp()
for i in range(T):
	a1 = inlt()
	(m, s) = (a1[0], a1[1])
	arr = inlt()
	print(sol(arr, m, s))


TT = int(input())
while TT:
	(m, s) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	sa = sum(a)
	ma = max(a)
	L = [i for i in range(1, ma + 1)]
	su = sum(L)
	need = su - sa
	if need == s:
		print('YES')
	elif need > s:
		print('NO')
	else:
		left = s - need
		while True:
			if left == 0:
				print('YES')
				break
			elif left < 0:
				print('NO')
				break
			ma += 1
			left -= ma
	TT -= 1


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
import math
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

def li():
	return list(map(int, sys.stdin.readline().split()))

def mp():
	return map(int, sys.stdin.readline().split())

def inp():
	return int(sys.stdin.readline())

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

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
t = inp()
for i in range(t):
	(n, s) = mp()
	l = li()
	m = max(l)
	vis = [0] * 1000
	for i in l:
		vis[i] = 1
	f = 0
	in1 = 0
	for i in range(len(vis)):
		if s == 0:
			f = 1
		if s < 0:
			in1 = i
			break
		if vis[i] == 0:
			s -= i
	if f == 1 and in1 >= m + 1:
		pr('YES')
	else:
		pr('NO')


for _ in range(int(input())):
	(m, s) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	ma = max(a)
	su = ma * (ma + 1) / 2 - sum(a)
	while True:
		if su == s:
			print('YES')
			break
		if su > s:
			print('NO')
			break
		ma += 1
		su += ma


t = int(input())
for i in range(t):
	(m, s) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	c = sum(l) + s
	a = ((1 + 8 * c) ** (1 / 2) - 1) / 2
	b = int(a)
	if a == b:
		for j in l:
			if j > b:
				print('NO')
				break
		else:
			d = 1
			e = l[0]
			for j in range(1, m):
				if l[j] == e:
					d += 1
				elif d > 1:
					print('NO')
					break
				else:
					d = 1
					e = l[j]
			else:
				print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(m, s) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	c = 1
	ans = []
	while s > 0:
		if c not in l:
			s -= c
			l = l + [c]
		c += 1
	if s == 0:
		if len(l) == max(l):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


for _ in range(int(input())):
	(m, s) = map(int, input().split())
	nums = set(map(int, input().split()))
	curr_max = max(nums)
	curr_sum = 0
	for i in range(1, curr_max + 1):
		if i not in nums:
			curr_sum += i
	if curr_sum > s:
		print('NO')
		continue
	while curr_sum < s:
		i += 1
		curr_sum += i
	if curr_sum == s:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(a, b) = map(int, input().split())
	lst = [int(i) for i in input().split()]
	lst.sort()
	n = 0
	j = 1
	while n < b:
		if j not in lst:
			lst.append(j)
			n += j
		j += 1
	ck = []
	for j in range(1, max(lst) + 1):
		ck.append(j)
	lst.sort()
	if ck == lst and n == b:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(m, s) = map(int, input().split())
	b = list(map(int, input().split()))
	b.sort()
	k = 1
	for j in range(m):
		if b[j] != k:
			if b[j] < k:
				s = -1
				break
			while k < b[j]:
				s -= k
				if s < 0:
					break
				k += 1
		k += 1
	while s > 0:
		s -= k
		k += 1
	if s == 0:
		print('YES')
	else:
		print('NO')


def cal(m, s, arr):
	t = sum(arr) + s
	x = int((1 + 8 * t) ** 0.5 - 1) // 2
	if x * x + x != 2 * t:
		return False
	p = list(range(x + 1))
	for k in arr:
		if k not in p:
			return False
	return True
for jj in range(int(input())):
	(m, s) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	if cal(m, s, arr):
		print('YES')
	else:
		print('NO')


import sys
from bisect import bisect_left, bisect_right
from heapq import heapify, heappush, heappop
from collections import deque
from math import gcd, sqrt, log10, log2, floor, ceil, sqrt
from collections import deque, defaultdict
input = sys.stdin.readline

def il():
	return [int(a) for a in input().strip().split()]

def ip():
	return input().strip()

def ii():
	return int(input())
mod = 1000000000 + 7
dx = [-1, -2, 1, 2, 2, -2, -1, 1]
dy = [2, 1, 2, 1, -1, -1, -2, -2]

def ans(arr, s):
	d = {}
	f = True
	for k in arr:
		if k <= 0:
			f = False
			break
		if k in d:
			f = False
			break
		else:
			d[k] = 1
	if not f:
		print('NO')
	else:
		i = 1
		m = max(d)
		while s > 0 or i < m:
			if i not in d:
				s -= i
			i += 1
		if s == 0:
			print('YES')
		else:
			print('NO')
for _ in range(ii()):
	(n, s) = il()
	arr = il()
	ans(arr, s)


t = int(input())
for i in range(t):
	line = input().split(' ')
	s = int(line[1])
	nums = set()
	line = input().split(' ')
	addedsum = 0
	for l in line:
		nums.add(int(l))
	for n in range(1, max(nums)):
		if n not in nums:
			nums.add(n)
			addedsum += n
	if addedsum == s:
		print('YES')
	elif addedsum > s:
		print('NO')
	else:
		j = max(nums) + 1
		while addedsum < s:
			addedsum += j
			if addedsum == s:
				print('YES')
			elif addedsum > s:
				print('NO')
			j += 1


for _ in range(int(input())):
	(m, s) = map(int, input().split())
	arr = list(map(int, input().split()))
	st = set(arr)
	i = 1
	while s > 0 or i < max(arr):
		if i not in st:
			s -= i
		i += 1
	print('NO' if s else 'YES')


import sys
from collections import *
sys.setrecursionlimit(10 ** 5)
itr = (line for line in sys.stdin.read().strip().split('\n'))
INP = lambda : next(itr)

def ni():
	return int(INP())

def nl():
	return [int(_) for _ in INP().split()]

def solve(m, s, arr):
	big = 0
	seen = {}
	for n in arr:
		if n not in seen:
			seen[n] = True
			big = max(big, n)
	nums = []
	for n in range(1, big + 1):
		if n not in seen:
			nums.append(n)
	p = [False] * (s + 1)
	if sum(nums) == s:
		print('YES')
		return
	a = sum(nums)
	cur = big + 1
	while a < s:
		a += cur
		nums.append(cur)
		cur += 1
	if a == s:
		print('YES')
	else:
		print('NO')
t = ni()
for _ in range(t):
	(m, s) = nl()
	arr = nl()
	solve(m, s, arr)


for z in range(int(input())):
	(n, s) = map(int, input().split())
	arr = list(map(int, input().split()))
	L = []
	for i in range(1, max(arr)):
		if i not in arr:
			L.append(i)
	s1 = sum(L)
	i = max(arr)
	while s1 < s:
		i += 1
		s1 += i
	if s1 == s:
		print('YES')
	else:
		print('NO')


def solution():
	(n, s) = (int(num) for num in input().split())
	b = {int(num) for num in input().split()}
	maximum = max(b)
	i = 1
	for i in range(1, maximum + 1):
		if i not in b:
			s -= i
	if s < 0:
		print('NO')
		return
	if s == 0:
		print('YES')
		return
	i = maximum + 1
	while s > 0:
		s -= i
		i += 1
	if s < 0:
		print('NO')
		return
	else:
		print('YES')
		return

def main():
	t = int(input())
	while t:
		solution()
		t -= 1
main()


nb_test_case = int(input())
for i in range(0, nb_test_case):
	lists = input().split()
	number_element = int(lists[0])
	missing_sum = int(lists[1])
	liste_element = input().split()
	liste_element = [int(i) for i in liste_element]
	sume = sum(liste_element)
	j = max(liste_element)
	while j * (j + 1) // 2 <= sume + missing_sum:
		if j * (j + 1) // 2 == sume + missing_sum:
			print('YES')
			j = -1
			break
		j += 1
	if j != -1:
		print('NO')


inputI = list(map(int, input().split()))
t = inputI[0]
for i in range(1, t + 1):
	(m, s) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	ma = max(arr)
	su = sum(arr)
	ss = ma * (ma + 1) // 2
	while ss < su + s:
		ma += 1
		ss = ma * (ma + 1) // 2
	if ma * (ma + 1) // 2 == su + s:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
pos = {i * (i + 1) // 2: i for i in range(1, 1000)}
for _ in range(int(input())):
	(m, s) = map(int, input().split())
	b = list(map(int, input().split()))
	temp = sum(b) + s
	if temp not in pos.keys():
		print('NO')
	else:
		full = set([i for i in range(1, pos[temp] + 1)])
		if sum(full - set(b)) != s:
			print('NO')
		else:
			print('YES')


import math
t = int(input())
s = set()
for i in range(1, 10000):
	s.add(i)
while t:
	(n1, n2) = map(int, input().split())
	l = list(map(int, input().split()))
	b = sum(l)
	count = n1
	c = n2
	for x in s:
		if x not in l:
			n2 -= x
			count += 1
			a = count * (1 + count) // 2
			if n2 == 0 and a == b + c:
				print('YES')
				break
			elif n2 < 0:
				print('NO')
				break
	t -= 1


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(m, s) = list(map(int, input().split()))
	nums = list(map(int, input().split()))
	seen = set(nums)
	if len(seen) != m:
		print('NO')
		continue
	_max = max(nums)
	for i in range(1, _max + 1):
		if i not in seen:
			s -= i
			seen.add(i)
	for i in range(1, 1276):
		if s <= 0:
			break
		if i not in seen:
			s -= i
	print(['NO', 'YES'][s == 0])


n = int(input())
for i in range(n):
	(m, s) = map(int, input().split())
	arr = [int(i) for i in input().split()]
	i = 1
	while True:
		if i not in arr:
			s -= i
			arr.append(i)
		i += 1
		arr.sort()
		if s == 0:
			if sum(arr) == (1 + arr[-1]) * arr[-1] * 0.5:
				print('YES')
			else:
				print('NO')
			break
		elif s < 0:
			print('NO')
			break


t = int(input())
for _ in range(t):
	(m, s) = map(int, input().split())
	arr = [int(i) for i in input().split()]
	biggest = max(arr)
	for i in range(1, biggest):
		if i not in arr:
			s -= i
	while s > 0:
		biggest += 1
		s -= biggest
	if s == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(m, s) = list(map(int, input().split()))
	b = list(map(int, input().split()))
	maxB = max(b)
	bol = [False for i in range(200)]
	for i in b:
		bol[i - 1] = True
	i = 1
	while s > 0:
		if not bol[i - 1]:
			s -= i
			bol[i - 1] = True
		i += 1
	if s == 0 and all(bol[:maxB - 1]):
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(m, s) = map(int, input().rstrip().split())
	arr = list(map(int, input().rstrip().split()))
	Max = max(arr)
	there = set()
	for i in arr:
		there.add(i)
	Sum = 0
	for i in range(1, Max):
		if i not in there:
			Sum += i
			there.add(i)
	if Sum == s:
		print('YES')
	elif Sum > s:
		print('NO')
	else:
		off = Max + 1
		while Sum < s:
			Sum += off
			off += 1
		print('YES' if Sum == s else 'NO')


def func():
	(m, s) = map(int, input().split())
	l = list(map(int, input().split()))
	st = set((i for i in l))
	if len(st) != len(l):
		print('NO')
		return
	sm = sum(l)
	total_sum = s + sm
	m = max(l)
	ans = 0
	while ans < total_sum:
		ans = m * (m + 1) // 2
		m += 1
	if ans == total_sum:
		print('YES')
	else:
		print('NO')
t = int(input())
for _ in range(t):
	func()


t = int(input())
for i in range(1, t + 1):
	(_, rem_sum) = [int(v) for v in input().split()]
	found = {int(v) for v in input().split()}
	max_ = max(found)
	for i in range(1, 200):
		if i in found:
			continue
		if i >= max_:
			if rem_sum == 0:
				print('YES')
				break
			elif rem_sum < 0:
				print('NO')
				break
		rem_sum -= i


t = int(input())

def analyzator(s, m, list1):
	k = sum(list1)
	i = 1
	p = k + s
	while k < p:
		if i not in list1:
			k += i
			list1.append(i)
		i += 1
		if k == p and len(list1) == max(list1):
			return 'YES'
	return 'NO'
for i in range(t):
	(m, s) = map(int, input().split())
	list1 = list(map(int, input().split()))
	f = analyzator(s, m, list1)
	print(f)


from math import ceil, factorial, gcd
mod = 998244353
for _ in range(int(input())):
	(m, s) = map(int, input().split())
	cnt = [0 for i in range(101)]
	arr = list(map(int, input().split()))
	vis = set()
	target = sum(arr) + s
	for i in range(1, 101):
		if target - i >= 0:
			target -= i
			vis.add(i)
	for i in arr:
		if i not in vis or target != 0:
			print('NO')
			break
	else:
		for i in range(1, max(vis)):
			if i not in vis:
				print('NO')
				break
		else:
			print('YES')


def check(n, s, b):
	m = max(b)
	tots = m * (m + 1) // 2
	oursum = tots - sum(b)
	if oursum == s:
		return 1
	elif oursum == 0:
		i = m + 1
		while s > 0:
			s = s - i
			i += 1
		if s == 0:
			return 1
		return 0
	elif s > oursum:
		s = s - oursum
		i = m + 1
		while s > 0:
			s = s - i
			i += 1
		if s == 0:
			return 1
		return 0
	else:
		return 0
t = int(input())
for _ in range(t):
	(n, s) = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	ans = check(n, s, b)
	if ans:
		print('YES')
	else:
		print('NO')


nlines = int(input())
for i in range(nlines):
	(m, s) = map(int, input().split())
	numbers = list(map(int, input().split()))
	numbers.sort()
	next = 1
	i = 0
	while next <= numbers[len(numbers) - 1]:
		if next != numbers[i]:
			s = s - next
		else:
			i = i + 1
		next = next + 1
	while s > 0:
		s = s - next
		next = next + 1
	if s < 0:
		print('NO')
	else:
		print('YES')


import sys

def main():
	t = int(sys.stdin.readline())
	for _ in range(t):
		(m, s) = map(int, sys.stdin.readline().split())
		ss = s
		arr = list(map(int, sys.stdin.readline().split()))
		mx = max(arr)
		st = set(list(range(1, mx + 1))) - set(arr)
		for a in st:
			ss -= a
		if ss < 0:
			print('NO')
		elif ss == 0:
			print('YES')
		else:
			i = mx + 1
			while ss > 0:
				ss -= i
				i += 1
			if ss < 0:
				print('NO')
			else:
				print('YES')
main()


import math
t = int(input())
for _ in range(t):
	(m, s) = [int(j) for j in input().split()]
	b = [int(x) for x in input().split()]
	s2 = s + sum(b)
	if int(math.sqrt(s2 * 2)) * (int(math.sqrt(s2 * 2)) + 1) / 2 == s2:
		if int(math.sqrt(s2 * 2)) < max(b):
			print('NO')
		else:
			print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(m, s) = map(int, input().split())
	b = list(map(int, input().split()))
	s1 = 0
	i = max(b)
	bn = list(range(1, i + 1))
	while s1 < s:
		s1 = sum(set(bn).difference(set(b)))
		bn.append(max(bn) + 1)
	if s1 == s:
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	(M, S) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	n = 1
	for i in range(M):
		a = A[i]
		while a > n:
			S -= n
			n += 1
		n += 1
	if S < 0:
		print('NO')
	elif S == 0:
		print('YES')
	else:
		n = A[-1] + 1
		while S > 0:
			S -= n
			n += 1
		if S == 0:
			print('YES')
		else:
			print('NO')


def solve():
	(m, s) = map(int, input().split())
	a = [int(i) for i in range(1, 100)]
	b = [int(i) for i in input().split()]
	t = 0
	for i in b:
		a.remove(i)
	for i in range(len(a)):
		s -= a[i]
		b.append(a[i])
		if s == 0:
			b.sort()
			for i in range(len(b) - 1):
				if b[i + 1] - b[i] > 1:
					print('NO')
					return
			print('YES')
			return
		if s < 0:
			print('NO')
			return
t = int(input())
for _ in range(t):
	solve()


n = int(input())
l = []
for i in range(n):
	(t, s) = map(int, input().split())
	nums = input().split()
	numbers = []
	for j in range(t):
		numbers.append(int(nums[j]))
	index = 1
	ss = 0
	while True:
		if numbers.__contains__(index) == False:
			ss += index
			numbers.append(index)
		if ss == s:
			thisMax = max(numbers)
			flag = True
			for k in range(1, thisMax + 1):
				if numbers.__contains__(k) == False:
					flag = False
					break
			if flag == True:
				l.append('YES')
				break
			elif flag == False:
				l.append('NO')
				break
		elif ss > s:
			l.append('NO')
			break
		index += 1
for i in range(len(l)):
	print(l[i])


def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
x = []
for i in range(t):
	l1 = list(invr())
	l2 = list(invr())
	x.append([l1, l2])
for i in x:
	s = i[0][1]
	b = i[1].copy()
	for j in range(1, 1000):
		if j not in b:
			b.append(j)
			s -= j
		if s <= 0:
			break
	if s < 0:
		print('NO')
	else:
		for j in range(1, max(b) + 1):
			if j not in b:
				print('NO')
				break
		else:
			print('YES')


t = int(input())
result = []
for i in range(t):
	(m, s) = map(int, input().split())
	b = list(map(int, input().split()))
	b.sort()
	for i in range(1, 1000):
		if i not in b:
			if s >= i:
				b.append(i)
				s -= i
				if s == 0 and max(b) * (max(b) + 1) / 2 == sum(b):
					result.append('YES')
					break
			else:
				result.append('NO')
				break
for i in result:
	print(i)


n = int(input())
a = []
for i in range(n):
	(g, h) = [int(i) for i in input().split()]
	k = [int(i) for i in input().split()]
	c = 1
	sum = 0
	while sum < h:
		if c not in k:
			sum += c
			k.append(c)
		c += 1
	if sum == h and len(k) >= max(k):
		a.append('YES')
	else:
		a.append('NO')
for i in a:
	print(i, end='\n')


t = int(input())
one = 1
zero = 0
ans1 = 'YES'
ans2 = 'NO'

def main():
	for q in range(t):
		(m, s) = map(int, input().split())
		array = list(map(int, input().split()))
		iter = one
		while s > 0:
			if not iter in array:
				s = s - iter
				array.append(iter)
			iter = iter + one
		maximum = max(array)
		ls = len(set(array))
		if s == zero and maximum == ls:
			print(ans1)
		else:
			print(ans2)
main()


for i in range(int(input())):
	(m, s) = input().split(' ')
	s = int(s)
	list1 = list(map(int, input().split(' ')))
	num = 1
	_sum = 0
	while 1:
		if num not in list1 and _sum <= s:
			_sum = _sum + num
			list1.append(num)
			if _sum == s:
				if len(list1) == max(list1):
					print('YES')
					break
				else:
					print('NO')
					break
			elif _sum > s:
				print('NO')
				break
		num = num + 1


t = int(input())

def solve(m, s, arr):
	arr = set(arr)
	s += sum(arr)
	i = 1
	while s > 0:
		if i in arr:
			arr.remove(i)
		s -= i
		i += 1
	if s == 0 and (not arr):
		return 'YES'
	return 'NO'
for i in range(t):
	(m, s) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	print(solve(m, s, arr))


num = int(input())
for i in range(0, num):
	(n1, n2) = input().split()
	n1 = int(n1)
	n2 = int(n2)
	li = input().split()
	li = [int(x) for x in li]
	nmax = max(li)
	mmax = max(nmax, n2)
	sam = n2 + sum(li)
	flag = 100
	for i in range(2, mmax + 1):
		sm = (i + 1) * i / 2
		if sm == sam and i >= nmax:
			flag = 1
			break
		elif sm == sam and i < nmax:
			flag = 0
			break
		elif sm > sam:
			flag = 0
			break
	if flag == 1:
		print('YES')
	else:
		print('NO')


def main(maximum, ssum):
	ssum = ssum - maximum * (maximum + 1) / 2
	counter = maximum + 1
	while ssum > 0:
		ssum = ssum - counter
		counter += 1
	if ssum < 0:
		return 'NO'
	return 'YES'
output = []
for test in range(int(input())):
	fl = [int(i) for i in input().split()]
	n = fl[0]
	m = fl[1]
	array = [int(i) for i in input().split()]
	mx = max(array)
	output.append(main(mx, m + sum(array)))
for o in output:
	print(o)


def solution():
	(m, s) = map(int, input().split())
	a = list(map(int, input().split()))
	c = 0
	i = 1
	while c < s:
		if i not in a:
			a.append(i)
			c += i
		i += 1
	tr = True
	for j in range(1, len(a) + 1):
		if j not in a:
			tr = False
	if c == s and tr == True:
		print('YES')
	else:
		print('NO')
for _ in [0] * int(input()):
	solution()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	i = 1
	while k > 0:
		if i not in A:
			A.append(i)
			k -= i
		i += 1
	flag = 0
	for x in range(1, max(A) + 1):
		if x not in A:
			flag = 1
			break
	if k == 0 and flag == 0:
		print('YES')
	else:
		print('NO')


init = int(input())

def missing_elements(copy):
	res = []
	for i in range(max(copy)):
		if i + 1 not in copy:
			res.append(i + 1)
	return res

def can_finish(seq):
	cur_sort = sorted(seq)
	missing = missing_elements(cur_sort)
	if len(missing) == 0 and s == cur_sort[-1] + 1:
		return 'YES'
	if len(missing) == 0 and s < cur_sort[-1] + 1:
		return 'NO'
	if sum(missing) == s:
		return 'YES'
	if sum(missing) > s:
		return 'NO'
	sofar = 0
	for i in missing:
		sofar += i
		seq.append(i)
	new = sorted(seq)
	while sofar + new[-1] + 1 <= s:
		add = new[-1] + 1
		new.append(add)
		sofar += add
	if sofar == s:
		return 'YES'
	else:
		return 'NO'
for i in range(init):
	(m, s) = map(int, input().split())
	cur = list(map(int, input().split()))
	print(can_finish(cur))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	x = 0
	i = 0
	l = list(map(int, input().split()))
	for i in range(max(l)):
		if i not in l:
			x += i
	while True:
		i += 1
		if i not in l:
			x += i
		if x > b:
			s = 'NO'
			break
		elif x == b:
			s = 'YES'
			break
	print(s)