#C5786. Minimum Operations to Cut All Grass
Minimum Operations to Cut All Grass
Minimum Operations to Cut All Grass
Given a square grid of size n (i.e. an \(n \times n\) grid), each cell contains a positive integer representing the height of the grass. You are allowed to perform the following operation: select any row or column and cut the grass in that line, which sets all the values in that row or column to zero. It can be proven that the minimum number of operations required to reduce every cell to 0 is exactly n, since cutting all rows (or equivalently all columns) will always suffice.
Example: For a grid of size 3, 3 operations will be required, and for a grid of size 4, 4 operations are required.
inputFormat
The first line of input contains a single integer (n) representing the size of the grid. The following (n) lines each contain (n) space-separated integers representing the heights of the grass in each cell.
outputFormat
Output a single integer, which is the minimum number of operations required to reduce all grass heights to zero.## sample
3
2 5 4
3 0 1
6 4 2
3
</p>