#B2102. Saddle Point in a 5x5 Matrix
Saddle Point in a 5x5 Matrix
Saddle Point in a 5x5 Matrix
Given a (5 \times 5) matrix where each row has a unique maximum element and each column has a unique minimum element, find the saddle point. The saddle point is defined as the element which is the maximum in its row and simultaneously the minimum in its column.
For example, consider the matrix below:
(
\begin{matrix}
11 & 3 & 5 & 6 & 9\
12 & 4 & 7 & 8 & 10\
10 & 5 & 6 & 9 & 11\
8 & 6 & 4 & 7 & 2\
15 & 10 & 11 & 20 & 25
\end{matrix}
)
The saddle point is 8 (located at the 4th row and 1st column).
inputFormat
The input consists of 5 lines. Each line contains 5 space-separated integers representing one row of the matrix.
outputFormat
Output a single line containing the saddle point value. If no saddle point exists, output "NO".
sample
11 3 5 6 9
12 4 7 8 10
10 5 6 9 11
8 6 4 7 2
15 10 11 20 25
8