cswork / OA打开练习工作台

CiscoOA #25

Find Number in Matrix

估计简单可在线判题

考点(AI 标注)原地数组

Find an element that is greater than or equal to every element in its row (ties allowed) and less than or equal to every element in its column; if one exists, output its value, otherwise −1. All valid positions necessarily have the same value.

输入格式

The input is N M, followed by N lines of M integers each. The original bounds 1≤N,M≤1000 and non-negative integers are kept; the original upper bound on elements is missing, and this site adds 0..10^9.

输出格式

Output a single integer, the answer.

样例 1

输入:

2 3
3 4 5
1 2 6

输出:

5

样例 2

输入:

2 2
1 1
0 1

输出:

1

样例 3

输入:

2 2
0 1
1 0

输出:

-1

样例说明

The outputs of the three public examples are, in order: 5; 1; -1. Verified by independent enumeration or direct simulation.