P1418 [TJOI2011] Construct a Matrix
Description
Construct an $n\times m$ $01$ matrix such that the number of $1$s in each row is $r_1,r_2,\ldots,r_n$, and the number of $1$s in each column is $c_1,c_2,\ldots,c_m$.
Among all valid matrices, the result should be lexicographically smallest. When comparing two matrices in lexicographical order, first compare the first row; if they are equal, compare the second row; and so on.
Input Format
The first line contains two integers $n,m$.
The second line contains $n$ integers $r_1,r_2,\ldots,r_n$.
The third line contains $m$ integers $c_1,c_2,\ldots,c_m $.
Output Format
Output an $n\times m$ matrix.
Explanation/Hint
For $100\%$ of the testdata, $n,m\le 100$.
Translated by ChatGPT 5