C2. Skibidus and Fanum Tax (hard version) codeforces solved by java

 C2. Skibidus and Fanum Tax (hard version)

time limit per test
2 seconds
memory limit per test
256 megabytes

This is the hard version of the problem. In this version, m2105.

Skibidus has obtained two arrays a and b, containing n and m elements respectively. For each integer i from 1 to n, he is allowed to perform the operation at most once:

  • Choose an integer j such that 1jm. Set ai:=bjai. Note that ai may become non-positive as a result of this operation.

Skibidus needs your help determining whether he can sort a in non-decreasing order by performing the above operation some number of times.

a is sorted in non-decreasing order if a1a2an.

Input

The first line contains an integer t (1t104) — the number of test cases.

The first line of each test case contains two integers n and m (1n21051m2105).

The following line of each test case contains n integers a1,a2,,an (1ai109).

The following line of each test case contains m integers b1,b2,,bm (1bi109).

It is guaranteed that the sum of n and the sum of m over all test cases does not exceed 2105.

Output

For each test case, if it is possible to sort a in non-decreasing order, print "YES" on a new line. Otherwise, print "NO" on a new line.

You can output the answer in any case. For example, the strings "yEs", "yes", and "Yes" will also be recognized as positive responses.

Example
Input
Copy
5
1 3
5
9 1 1000000000
3 2
1 4 3
3 4
4 3
2 4 6 5
6 1 8
5 2
6 4 5 4 5
4 1000
3 1
9 8 7
8
Output
Copy
YES
NO
YES
NO
YES
Note

In the first test case, [5] is already sorted.

In the second test case, it can be shown that it is impossible.

In the third test case, we can set a2:=b1a2=64=2 and a3:=b3a3=86=2. The sequence [2,2,2,5] is in nondecreasing order.

In the last case, we can apply operations on each index. The sequence becomes [1,0,1], which is in nondecreasing order.


Post a Comment

Previous Post Next Post