#C4850. Minimum Operations to Zero in a Grid
Minimum Operations to Zero in a Grid
Minimum Operations to Zero in a Grid
You are given a grid of digits represented as strings. In one operation, you can reduce any digit by 1. However, the goal is not to simulate the operations, but to determine the minimum number of operations required to make every digit in the grid equal to 0.
It turns out that the minimum required operations is equal to the maximum digit present in the grid. Formally, if the grid is given by a set of strings, then you need to compute
( \max_{1 \leq i \leq N,, 1 \leq j \leq M} grid_{ij} )
where \(grid_{ij}\) is the digit at the \(i\)th row and \(j\)th column, and all digits are between 0 and 9.
Your task is to determine the answer using an efficient solution.
inputFormat
The first line contains two integers \(N\) and \(M\) representing the number of rows and the number of columns in the grid respectively.
The next \(N\) lines each contain a string of length \(M\) consisting of digits (from '0' to '9').
outputFormat
Print a single integer which is the minimum number of operations needed so that every digit in the grid becomes 0.
## sample3 3
123
456
789
9