#K70942. Maximum Column Values

    ID: 33420 Type: Default 1000ms 256MiB

Maximum Column Values

Maximum Column Values

You are given a rectangular matrix of positive integers. The task is to compute the maximum value for each column and output these maximum values in order. Formally, given a matrix \(A\) with \(n\) rows and \(m\) columns, you need to find:

[ max_i = \max_{1 \leq j \leq n} A_{j,i} \quad \text{for } i = 1, 2, \ldots, m, ]

If the matrix is empty (i.e. there are no rows or no columns), the output should be empty. Note that each test case is provided via stdin and the result should be printed to stdout as space-separated integers in one line.

Examples:

  • For the matrix [[1, 2, 3]] the output is 1 2 3.
  • For the matrix [[1, 2, 3], [4, 5, 6]] the output is 4 5 6.
  • For the matrix [[10, 20, 30], [15, 25, 35], [5, 10, 15]] the output is 15 25 35.

inputFormat

The input is read from stdin in the following format:

  • The first line contains two integers \(n\) and \(m\) representing the number of rows and columns respectively.
  • The next \(n\) lines each contain \(m\) space-separated positive integers, which represent the rows of the matrix.

If \(n=0\) or \(m=0\), the matrix is considered empty and the output should be empty.

outputFormat

Output a single line to stdout that contains \(m\) space-separated integers representing the maximum element found in each column of the matrix. If the matrix is empty, output nothing.

## sample
1 3
1 2 3
1 2 3