Submit | All submissions | Best solutions | Back to list |
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
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 |
hide comments
|
|||||
2016-03-02 04:10:07
o(n) is accepting |
|||||
2016-03-01 21:30:33
Easy ;) |
|||||
2016-02-23 15:48:34 Siddharth Singh
Nice , All You Should Have Is IQ For This Qstn AC 1st Shot. On The Top ;) Last edit: 2016-02-24 14:03:41 |