C. Roy and Peak Array

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] or B[i] > A[i-1] and B[i] > A[i+1]

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 integers A[1], A[2], ..., A[N]. (1 ≤ A[i] ≤ \(10^9\))
  • The third line contains N integers B[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
4
4
1 3 2 4
5 6 7 5
1
10
10
4
1 2 3 4
1 2 4 4
6
3 2 2 1 3 1
4 5 6 7 6 6 
Yes
Yes
No
Yes

Brain Booster #10

Not Attended
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