All Tracks Algorithms Sorting Problem

Game of survival
/

Algorithms

Problem
Editorial
Analytics

Alice is stuck on an island. The island has N animals. The ith animal has strength A[i]. Fortunately, Alice has N swords. ith 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 ith element is the sharpness of Alice's ith sword. It is followed by N elements where ith 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
Time Limit: 5.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB

Best Submission

Similar Problems

Contributors

This Problem was Asked in

Initializing Code Editor...
Notifications
View All Notifications

?