Adjacent Sort

3

1 votes
Problem

Given n elements in an array.

You are required to sort the array in non-decreasing order the value of the element.

The elements are represented by two integers

ai – the value of the element

bi – the type of the element {0 or 1}.

He can do so by performing below operation any no of times:

  • Select any two indices i and j such that bi ≠ bi and | i-j = 1 and swap them. (That is you can select any two adjacent elements and swap them if they both are of a different type).

Can you sort the elements in non-decreasing order?


INPUT:

The first line contains one integer t(1 ≤ t ≤ 20) — the number of test cases. The description of the test cases follows.

The first line of each test case contains one integer n(1 ≤ n ≤ 105) — the size of the arrays.

The second line contains n integers ai(1 ≤ a≤ 105)  — the value of the ith element.

The third line containts n integers bi bi ∈ {0,1} )  — the type of the ith element.

30% of test cases- (1 ≤ n ≤ 10)


OUTPUT:

For each test case, print "YES" or "NO" (without quotes) depending on whether it is possible to sort elements in non-decreasing order of their value.

Print each letter in Upper case only.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For first test you can first swap 2nd element with third element then 3rd element with 4th element.

second test: all elements are already sorted

third test: you cannot perform swap operation.

Editor Image

?