#K49987. Construct Binary Matrix
Construct Binary Matrix
Construct Binary Matrix
Given two positive integers \(n\) and \(m\), construct an \(n \times m\) binary matrix such that each row and each column contains at most one \(1\). The matrix should be constructed by placing a single \(1\) in each row in the first \(n\) columns (i.e., forming an identity matrix in the top-left corner) and filling the remaining positions with \(0\). If it is impossible to construct such a matrix, output \(-1\).
For example, when \(n=3\) and \(m=4\), a valid matrix is:
\[
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0
\end{bmatrix}
\]
Note: It is impossible to construct the matrix if \(n > m\), in which case the output should be \(-1\).
inputFormat
Input is read from standard input (stdin) and consists of two space-separated positive integers \(n\) and \(m\), where \(n\) is the number of rows and \(m\) is the number of columns.
outputFormat
If a valid matrix can be constructed, print the matrix to standard output (stdout) with each row printed on a new line and the numbers in each row separated by a single space. If it is impossible to construct the matrix, print \(-1\) (without quotes).
## sample3 4
1 0 0 0
0 1 0 0
0 0 1 0
</p>