Eastern Crossword
Marisya enjoys solving nonograms, a type of puzzle where you fill in cells of an (N M) grid. Each column and each row must have a specific number of filled cells, as indicated by numbers in the margins. However, sometimes these puzzles are unsolvable due to errors by the creators, and Marisya wants to avoid wasting time on such puzzles.
**Task**
Your task is to write a program that checks whether a given nonogram puzzle is solvable based on the provided dimensions (N) and (M), and the numbers in the margins.
**Input**
The first line of the input contains the integer (1 ≤ T ≤ 5), representing the number of puzzles to evaluate. Each puzzle is described over three lines:
- The first line contains two natural numbers (M) and (N) (both not exceeding (10^5)), representing the width and height of the puzzle. - The second line lists (N) non-negative integers, each indicating the number of filled cells required in the corresponding column. - The third line lists (M) non-negative integers, each indicating the number of filled cells required in the corresponding row.
All numbers in the second and third lines do not exceed the total number of cells in their respective column or row.
**Output**
For each puzzle, output a single line containing 1 if the puzzle is solvable, or 0 if it is not. The results should be in the same order as the puzzles are presented in the input.
**Scoring**
The test set is divided into three blocks with additional conditions:
1. 152. 353. 50**Explanation**
In the first example, the puzzle can be solved as shown in the provided image. In the second example, the puzzle is unsolvable because the row constraints require all columns to be fully filled, while the column constraints require no filled cells, which is contradictory.