#C6492. Matrix Addition and Formatting

    ID: 50258 Type: Default 1000ms 256MiB

Matrix Addition and Formatting

Matrix Addition and Formatting

You are given two matrices A and B of the same dimensions \(n \times m\). Your task is to compute a new matrix C where each element \(c_{ij}\) is the sum of the corresponding elements from A and B, i.e., \(c_{ij} = a_{ij} + b_{ij}\). After computing the matrix, you should format it such that each row is printed on a new line with its elements separated by a single space.

The input will be provided via standard input (stdin) and the output must be printed to standard output (stdout) in the specified format.

inputFormat

The input begins with a line containing two space-separated integers \(n\) and \(m\) indicating the number of rows and columns, respectively. The next \(n\) lines each contain \(m\) space-separated integers representing the elements of matrix A. This is followed by another \(n\) lines, each with \(m\) space-separated integers which represent the elements of matrix B.

For example:

2 3
1 2 3
4 5 6
-1 -2 -3
-4 -5 -6

outputFormat

Output the resulting matrix C where each element is the sum of the corresponding elements from A and B. Each row of the matrix should be printed on a new line with each element separated by a single space.

For example, the sample input above produces:

0 0 0
0 0 0
## sample
2 3
1 2 3
4 5 6
-1 -2 -3
-4 -5 -6
0 0 0

0 0 0

</p>