#C7253. Maximal Height Difference in a Matrix

    ID: 51104 Type: Default 1000ms 256MiB

Maximal Height Difference in a Matrix

Maximal Height Difference in a Matrix

You are given a matrix of integers representing heights. Your task is to compute the difference between the highest and the lowest values in the matrix.

The theoretical idea can be expressed with the following formula:

[ \text{Difference} = \max_{(i,j)} a_{ij} - \min_{(i,j)} a_{ij} ]

where \(a_{ij}\) represents the element at row \(i\) and column \(j\) of the matrix.

This problem tests your ability to parse a two-dimensional array, process it, and perform basic arithmetic operations.

inputFormat

The input is read from standard input (stdin) and has the following format:

The first line contains two space-separated integers (n) and (m), representing the number of rows and columns, respectively. Each of the following (n) lines contains (m) space-separated integers, which are the elements of the matrix.

outputFormat

Output to standard output (stdout) a single integer: the difference between the maximum and minimum element in the matrix.## sample

3 3
1 2 3
4 5 6
7 8 9
8