#K69647. Minimum Number of Operations to Transform Grid

    ID: 33133 Type: Default 1000ms 256MiB

Minimum Number of Operations to Transform Grid

Minimum Number of Operations to Transform Grid

You are given a grid with n rows and m columns. Initially, all the cells in the grid are 0. You are also given a target configuration represented by a matrix T of size n × m. Your task is to transform the initial grid to exactly match the target configuration using a series of operations.

In one operation, you can select any cell at position (i, j) (1-indexed) and add a positive integer k (i.e. k > 0) to every cell in the submatrix whose top-left corner is (i, j) and bottom-right corner is (n, m). In other words, for every cell (x, y) satisfying $$ i \le x \le n \quad \text{and} \quad j \le y \le m, $$ you add k to that cell.

Find the minimum total sum of the integers added over all operations required to exactly achieve the target grid.

Note: The total sum of all increments used in the operations is considered as the answer.

inputFormat

The first line contains two integers n and m, representing the number of rows and columns of the grid, respectively.

The following n lines each contain m integers separated by spaces, where the j-th integer in the i-th line represents T[i][j], the target value at that cell.

outputFormat

Output a single integer: the minimum total amount added over all operations to transform the grid to the target configuration.

## sample
3 3
1 0 1
2 1 1
2 1 2
2