All submissions for this problem are available.
Little Anuj is lost!!! Help him find his way back to home. Anuj is sure that his home is either to the left or to the right from where he's standing. He has two sets of moves A,B, where A,B is a finite subset of the positive integers.
He is confused to such an extent that he moves left and right alternatively. On every odd-numbered step, he moves 'A' moves to the right. While on every even-numbered step, he moves 'B' moves to the left. Consider his starting position as 0, and the first step he takes as step no. 1.
Since Anuj is not sure of his whereabouts, help him judge that from the given set of A,B, it is true that for every integer z (both the positives and the negatives), that Anuj can eventually reach z.
The first line contains a positive integer t, the number of test cases (1 <= t <= 1000). The first line of each test case then contains x and y, denoting the size of the sample space of A and B, respectively. The x lines following this line denote the elements in set A. The next y lines denote the elements is set B. The 'element' can be any positive number from 1 to 1000000.
For each test case output in a newline "YES" if Anuj can eventually reach all integers.
Else output in a newline "NO" if it is not possible for him to reach all integers.
Input: 2 1 1 2 2 2 2 1 2 1 2 Output: NO YES
|Time Limit:||0.12 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, GO, NODEJS, PYP3|
Fetching successful submissions
If you are still having problems, see a sample solution here.