Two matrices with Nrows and columns are given M. Let P[i][j]and A[i][j]be an element of the jthrow of the ithfirst and second matrices, respectively. Now we want to make each element of the second matrix zero. In each turn, we must select five integers:
1 ≤ x1 ≤ x2 ≤ N
1 ≤ y1 ≤ y2 ≤ M
0 ≤ k ≤ 10000
and after that for all pairs (i,j)such that:
x1 ≤ i ≤ x2
y1 ≤ j ≤ y2
The following operation is performed:
A[i][j] = (k + A[i][j]) % P[i][j]
Now, I want to make the matrix Azero in the minimum moves. What would be best besides selecting each item and increasing it with a difference P[i][j]-A[i][j].
Example: let's say that we have N=2and M=2, and the matrix Pis
1 2
2 3
And let the AMatrix be
0 1
1 1
Then here the minimum moves are 2:
1: (1,1) (2,2) 1
2: (2,2) (2,2) 1
, , .
x1, y1, x2, y2 k .
: N M 100. P[i][j] 10, A[i][j] P[i][j].