NINJA1 - Related or not
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 ≤ 105
0 ≤ Ai, Bi ≤ 1010
Sample:
Input: 3 3 1 2 3 4 4 4 3 3 2 1 6 5 4 2 1 0 10 2 Output: YES NO YES
hide comments
gurugs:
2016-03-02 04:10:07
o(n) is accepting |
|
street_funker:
2016-03-01 21:30:33
Easy ;) |
|
Siddharth Singh:
2016-02-23 15:48:34
Nice , All You Should Have Is IQ For This Qstn
|
Added by: | mombassa |
Date: | 2016-02-17 |
Time limit: | 1s-1.5s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 GOSU JS-MONKEY |