C. Roy and Peak Array
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
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
N
integersA[1], A[2], ..., A[N]
. (1 ≤ A[i] ≤ \(10^9\)) - The third line contains
N
integersB[1], B[2], ..., B[N]
. (1 ≤ B[i] ≤ \(10^9\)) - sum of
N
overall 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 |
---|---|
|
|
Brain Booster #10
- Status
- Done
- Rule
- ACM/ICPC
- Problem
- 6
- Start at
- 2025-06-13 15:30
- End at
- 2025-06-13 18:00
- Duration
- 2.5 hour(s)
- Host
- Partic.
- 91