#C8727. Minimum Pop Operations
Minimum Pop Operations
Minimum Pop Operations
Given an n x m grid of non-negative integers, you are allowed to perform a pop operation which subtracts 1 from every positive element in the grid. In other words, during a single pop operation, every cell with a value greater than zero is reduced by 1.
The task is to determine the minimum number of pop operations required to reduce all the values in the grid to 0.
Mathematically, if the grid is represented as \(grid\) and \(\max(grid)\) denotes the maximum value in the grid, then the answer is:
[ \text{answer} = \max(grid) ]
This is because each operation decreases all non-zero elements by 1, so we must perform as many operations as the largest number in the grid.
inputFormat
The first line of input contains two integers n
and m
(1 ≤ n, m ≤ 1000) representing the number of rows and columns in the grid. This is followed by n
lines, each containing m
space-separated non-negative integers, representing the grid.
For example:
3 3 1 1 1 1 1 1 1 1 1
outputFormat
Output a single integer, the minimum number of pop operations required to reduce all values in the grid to 0.
For the sample input above, the output is:
1## sample
3 3
1 1 1
1 1 1
1 1 1
1