Problems > Saddle Points

Saddle Points

Difficulty: 1300 2000 ms 128 MB

implementation

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

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.