cswork / OA打开练习工作台

CiscoOA #3

Saddle Point in Matrix

估计简单可在线判题

考点(AI 标注)原地数组

The matrix elements are non-negative. Find an element that equals both the maximum of its row and the minimum of its column, and output its value; if none exists, output −1. Multiple equal maximum or minimum positions are all valid; it does not need to be strictly greater or smaller.

输入格式

The first line contains N M, followed by N lines of M integers each. Original bounds: 1≤N,M≤1000; the elements are non-negative but have no upper bound, so this site adds ≤10^9. The next sentence of the original input swapped the dimensions as M rows and N columns; this site restores N rows and M columns based on the explicit dimension definition.

输出格式

Output a single integer, the answer.

样例 1

输入:

2 2
1 2
3 4

输出:

2

样例 2

输入:

2 2
1 1
0 1

输出:

1

样例 3

输入:

2 2
2 1
1 2

输出:

-1

样例说明

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