Time limit
Memory limit
The best StarCraft team on the west side of the city is Jimin's team, and the best on the east side is Hansu's team. The two teams decide to face off to settle who is the best in the city.
Jimin's team has $N$ players and Hansu's team has $M$ players. Each player has a fixed number of games they must play, and this number may differ from player to player.
The match table must satisfy all of the following rules.
The table is an $N \times M$ matrix. Rows correspond to Jimin's team and columns to Hansu's team. If cell $(i, j)$ is $1$, then player $i$ of Jimin's team plays against player $j$ of Hansu's team; if it is $0$, they do not play.
The lexicographic comparison of two tables is defined as follows. First find the first row $i$ in which the two matrices differ, then find the first column $j$ in that row where they differ. The table with $0$ in cell $(i, j)$ comes first.
Given the number of games each player on each team must play, write a program that prints the lexicographically smallest table.
The first line contains $N$, the number of players on Jimin's team, and $M$, the number of players on Hansu's team. The second line lists the number of games each player on Jimin's team must play, and the third line lists the number of games each player on Hansu's team must play. $N$ and $M$ are natural numbers at most $50$, and each game count is a natural number at most $50$ or $0$.
Print the table on $N$ lines. Each line is an $M$-character string formed by concatenating that row's values with no separators. If no valid table exists, print $-1$.