game-of-survival

Alice is stuck on an island. The island has N animals. The i^th animal has strength A[i]. Fortunately, Alice has N swords. i^th sword has sharpness S[i]. Alice can kill an animal with a sword if and only if its sharpness is strictly greater than the strength of the animal. After killing the animal, its sharpness becomes 0. Alice wants to know if he can kill all the animals and escape from the island. Help him to know the same.

Input 
First line of the input contains the number of test cases T. It is followed by T tets cases. Each test case has 3 lines. First line contains the number of animals N.  It is followed by a line containing N elements where i^th element is the sharpness of Alice's ith sword. It is followed by N elements where i^th element is the strength of the animal i.

Output
For each test case output "YES" if Alice can kill all the animals. Else print "NO".  

Constraints
1 ≤ N ≤ 10^5 
1 ≤ S[i], A[i] ≤ 100  where 0 ≤ i < N

Read the editorial here.

SAMPLE INPUT
4
5
81 79 43 96 19 
73 89 73 30 24 
5
10 61 55 88 17 
15 76 21 73 19 
5
101 67 63 101 76 
34 85 25 20 6 
5
58 9 76 23 16 
97 94 16 18 9 

SAMPLE OUTPUT
NO
NO
YES
NO

Difficulty: MEDIUM

Starter code:

Solutions:
cases = int(input())
for i in range(cases):
	n = int(input())
	swords = []
	for k in range(n):
		value = int(input())
		swords.append(value)

	animals = []
	for a in range(n):
		value = int(input())
		animals.append(value)

	swords.sort()
	animals.sort()
	killedAll = 1

	for j in range(n):
		if animals[j] >= swords[j]:
			print("NO")
			killedAll = 0
			break

	if killedAll == 1:
		print("YES")


t=int(input())
while t:
	t-=1
	a=[]
	b=[]
	n=int(input())
	for i in range(n):
		temp=int(input())
		a.append(temp)
	for i in range(n):
		temp=int(input())
		b.append(temp)
		
	a.sort()
	b.sort()
	flag=True
	for i in range(n):
		if(a[i]<=b[i]):
			flag=False
	if(flag):
		print("YES")
	else:
		print("NO")


t = int(input())

for _ in range(t):
	n = int(input())
	
	s = []
	a = []
	
	for i in range(n):
		data = int(input())
		s.append(data)
	for i in range(n):
		data = int(input())
		a.append(data)
	
	s.sort()
	a.sort()

	for i in range(n):
		if s[i] < a[i]:
			break
	
	if i==n-1:
		print("YES")
	else:
		print("NO")


def can_kill(s,a):
	s=sorted(s)
	a=sorted(a)
	kill=True
	for i in range(len(s)):
		if s[i]<=a[i]:
			kill=False
			break
	if kill:
		print("YES")
	else:
		print("NO")
	
if __name__ == "__main__":
	t=int(input())
	while t>0:
		n=int(input())
		if n>=1 and n<=10**5:
			s=[]
			a=[]
			for i in range(n):
				s.append(int(input()))
			for i in range(n):
					a.append(int(input()))
			can_kill(s,a)
		t-=1


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
for i in range(int(input())):
	m = int(input())
	s = []
	st = []
	for i in range(m):
		s.append(int(input()))
	for i in range(m):
		st.append(int(input()))
	s=sorted(s)
	st=sorted(st)
	g = 0
	for i in range(m):
		if s[i] <= st[i]:
			g = 1
			break
	if g == 1:
		print("NO")
	else:
		print("YES")



t = int(input())
 
for _ in range(t):
	n = int(input())
	
	s = []
	a = []
	
	for i in range(n):
		data = int(input())
		s.append(data)
	for i in range(n):
		data = int(input())
		a.append(data)
	
	s.sort()
	a.sort()
 
	for i in range(n):
		if s[i] < a[i]:
			break
	
	if i==n-1:
		print("YES")
	else:
		print("NO")


tc = int(input())
for test in range(tc):
	n = int(input())
	slist = []
	alist = []
	#slist = [ int(x) for x in raw_input().split() ]
	#alist = [ int(x) for x in raw_input().split() ]
	for n1 in range(n):
		temp = int(input())
		slist.append(temp)
	for n2 in range(n):
		temp1 = int(input())
		alist.append(temp1)


	if len(slist)<len(alist):
		print("NO")
	else:
		slist.sort(reverse = True)
		alist.sort(reverse = True)

		for mem in range(len(alist)):
			if slist[mem] > alist[ mem] :
				pass
			else:
				print("NO")
				break
		else:
			print("YES")


for i in range(int(input())):
	m = int(input())
	sharpness = [];
	strength = [];
	for i in range(m):
		sharpness.append(int(input()))
	for i in range(m):
		strength.append(int(input()))
	sharpness.sort()
	strength.sort()
	flag = 0
	for i in range(m):
		if sharpness[i] <= strength[i]:
			flag = 1
			break
	if flag == 1:
		print("NO")
	else:
		print("YES")


t = int(eval(input()))

for _ in range(t):
	n = int(eval(input()))
	
	s = []
	a = []
	
	for i in range(n):
		data = int(eval(input()))
		s.append(data)
	for i in range(n):
		data = int(eval(input()))
		a.append(data)
	
	s.sort()
	a.sort()
	
	for i in range(n):
		if s[i] < a[i]:
			break
	
	if i==n-1:
		print("YES")
	else:
		print("NO")