#C10877. Find the Smallest Element Not Less Than K in a Sorted Matrix

    ID: 40130 Type: Default 1000ms 256MiB

Find the Smallest Element Not Less Than K in a Sorted Matrix

Find the Smallest Element Not Less Than K in a Sorted Matrix

Given a matrix where each row is sorted in non-decreasing order, your task is to find the smallest element in the matrix that is greater than or equal to a given integer (k). If no such element exists, output -1.

Note: The matrix is provided in row-major order and you are required to process the entire matrix to determine the answer.

inputFormat

The first line of input contains two integers (m) and (n) representing the number of rows and columns respectively. This is followed by (m) lines, each containing (n) space-separated integers representing the matrix. The last line of input contains the integer (k).

outputFormat

Output a single integer: the smallest element in the matrix which is greater than or equal to (k). If no such element exists, output -1.## sample

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