Saddle Points
A cell is a saddle point if it is the minimum of its row and simultaneously the maximum of its column. Count the saddle points.
Input: the first line has N and M; the next N lines each have M integers.
Output: the number of saddle points.
Constraints:
- 1 ≤ N, M ≤ 100
- −104 ≤ values ≤ 104
Sample Tests
Input 1
3 3 1 2 3 4 5 6 7 8 9
Output 1
1
Input 2
2 2 1 1 1 1
Output 2
4
Discussion (opens after you solve — no spoilers before)
No comments yet.