spoj#NINJA1. Related or not
Related or not
Problem statement:
You are given two DNA sequences A and B. It is said that these two DNA sequences are related if there exists a non-decreasing sequence C of the same length, such that Ci = Ai or Ci = Bi. Find if the given sequences are related.
Input format:
The first line contains an integer, T, the number of test cases.
For each test case:
The first line contains an integer,N, the length of the DNA sequence.
The second line contains a sequence of space-separated integers describing species A.
The third line contains a sequence of space-separated integers describing species B.
Output Format
On a new line for each test case, print YES if a non-decreasing sequence of the same length can be found or NO if it cannot.
Constraints:
1 ≤ T ≤ 5
1 <= N <= 10 ^ 5
0 ≤ Ai, Bi ≤ 10 ^ 10
Sample input:
3
3
1 2 3
4 4 4
3
3 2 1
6 5 4
2
1 0
10 2
Sample Output:
YES
NO
YES