#K83597. Book Placement on Shelves
Book Placement on Shelves
Book Placement on Shelves
You are given T test cases. In each test case, there are two integers M and N denoting the number of shelves and the number of books respectively. This is followed by a line with M integers representing the weight capacities of the shelves and another line with N integers representing the weights of the books.
The objective is to determine whether it is possible to place each book on a unique shelf such that the weight of the book does not exceed the shelf's capacity. In other words, for each assigned book with weight (w_i) and its shelf with capacity (c_j), it must hold that (w_i \le c_j). If no assignment satisfying these constraints exists, output NO
; otherwise, output YES
. Note that if there are no books, the answer is considered YES
.
inputFormat
The input is read from standard input (stdin) and has the following format:
The first line contains an integer T, the number of test cases.
For each test case, the first line contains two space‐separated integers M and N.
The second line contains M space‐separated integers representing the capacities of the shelves. (If M is 0, this line will be empty.)
The third line contains N space‐separated integers representing the weights of the books. (If N is 0, this line will be empty.)
outputFormat
For each test case, output a single line to standard output (stdout) containing either YES
or NO
depending on whether it is possible to place all the books on the shelves under the given constraints.## sample
7
3 4
10 50 30
15 5 25 10
4 2
20 15 10 5
10 20
3 0
10 50 30
0 2
1 2
10
5 6
2 2
10 5
5 10
3 2
10 5 1
4 5
NO
YES
YES
NO
NO
YES
YES
</p>