CF2248B Merge to Match
Description
You are given two arrays $ a $ and $ b $ of lengths $ n $ and $ m $ , respectively. All $ n + m $ integers in these arrays are distinct.
You can perform the following operation on $ a $ any number of times (possibly, zero):
- Choose two elements of $ a $ with values $ x $ and $ y $ , where $ x \le y $ .
- Delete these two elements from $ a $ .
- Insert one integer $ z $ into $ a $ such that $ x \le z \le y $ .
After performing all operations, you may arrange the elements of $ a $ in any order.
Determine whether it is possible to make $ a $ equal to $ b $ .
Input Format
Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 10^4 $ ). The description of the test cases follows.
The first line of each test case contains two integers $ n $ and $ m $ ( $ 1 \le n, m \le 2 \cdot 10^5 $ ) — the lengths of the arrays $ a $ and $ b $ .
The second line contains $ n $ integers $ a_1, a_2, \ldots, a_n $ ( $ 1 \le a_i \le 10^9 $ ).
The third line contains $ m $ integers $ b_1, b_2, \ldots, b_m $ ( $ 1 \le b_i \le 10^9 $ ).
It is guaranteed that all $ n + m $ integers in the arrays $ a $ and $ b $ are distinct.
It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 2 \cdot 10^5 $ .
It is guaranteed that the sum of $ m $ over all test cases does not exceed $ 2 \cdot 10^5 $ .
Output Format
For each test case, print "YES" if it is possible to make $ a $ equal to $ b $ , and "NO" otherwise.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
Explanation/Hint
In the first test case, choose $ 1 $ and $ 3 $ , delete them, and insert $ 2 $ .
In the second test case, it can be shown that no sequence of operations can make $ a $ equal to $ b $ .
In the third test case, choose $ 1 $ and $ 5 $ , delete them, and insert $ 4 $ . Then, choose $ 3 $ and $ 7 $ , delete them, and insert $ 6 $ .
In the sixth test case, first choose $ 1 $ and $ 10 $ , delete them, and insert $ 5 $ . Next, choose $ 6 $ and $ 100 $ , delete them, and insert $ 90 $ . Finally, choose $ 4 $ and $ 5 $ , delete them, and insert $ 5 $ .
In the seventh test case, for the pairs $ (1,4) $ , $ (10,20) $ , and $ (30,40) $ , delete both elements and insert $ 3 $ , $ 15 $ , and $ 35 $ , respectively.
In the ninth test case, delete the pairs $ (1,3) $ , $ (8,18) $ , and $ (25,30) $ and insert $ 2 $ , $ 15 $ , and $ 28 $ , respectively. Then, delete $ 12 $ and $ 15 $ and insert $ 15 $ .
In the tenth test case, first choose $ 1 $ and $ 2 $ , delete them, and insert $ 2 $ . Then, choose $ 2 $ and $ 3 $ , delete them, and insert $ 3 $ . Finally, choose $ 3 $ and $ 5 $ , delete them, and insert $ 4 $ .