LearnPy Hub
← Arena
IntermediateRating 1200

Negatives in a Sorted Grid

Rows and columns are sorted in non-increasing order. Count the negative numbers in O(r + c).

Input

r c, then r lines.

Output

A count.

Sample 1

Input
4 4
4 3 2 -1
3 2 1 -1
1 1 -1 -2
-1 -1 -2 -3
Output
8

Sample 2

Input
2 2
3 2
1 0
Output
0
solution.py
Output appears here
Negatives in a Sorted Grid · Python Arena problem · LearnPy Hub