C. Roy and Peak Array
Time Limit: 2.0 s
Memory Limit: 256.0 MB
Description
You are given two integer arrays, A and B, each containing N elements. You may independently reorder the elements of A and B in any way you choose. After reordering, we say that array is peak,if the following condition satisfied:
For every index i with 2 ≤ i ≤ N−1 :
- Either
A[i] > B[i-1] and A[i] > B[i+1]orB[i] > A[i-1] and B[i] > A[i+1]
- Either
Your task is to determine whether the two arrays (A or B) can be reordered so that it satisfies the cross-peak condition against the other array .
Input
- First line
T(1 ≤ T ≤ 4000)- the number of test case. - In each test , first line
N( 1 ≤ N ≤ \(2 * 10^5\) ), the length of the array. - The second line contains
NintegersA[1], A[2], ..., A[N]. (1 ≤ A[i] ≤ \(10^9\)) - The third line contains
NintegersB[1], B[2], ..., B[N]. (1 ≤ B[i] ≤ \(10^9\)) - sum of
Noverall test case doesn't exceed \(2 * 10^5\).
Output
In each test case: Print Yes if array is peak, otherwise print No.
Sample
| Input | Output |
|---|---|
|
|
Information
- ID
- 1193
- Difficulty
- 6
- Category
- Brute_Force Click to Show
- Tags
- # Submissions
- 222
- Accepted
- 7
- Accepted Ratio
- 3%
- Uploaded By
Related
In following contests: