Official

B - Plus Matrix Editorial by evima


We can assume that the minimum value in \(A\) is \(0\), because if there is some pair \(A, B\) satisfying the condition such that the minimum value in \(A\) is \(m(>0)\), we can subtract \(m\) from all elements in \(A\) and add \(m\) to all elements in \(B\), and the pair still satisfies the condition.

If the minimum element in \(A\) is \(0\), we can determine \(A\) as \(A_i=C_{i,0}-m\), where \(m\) is the minimum value among \(C_{i,0}\), and \(B\) as \(B_j=C_{0,j}-A_0\).

Lastly, we check if this pair \(A, B\) actually satisfies all conditions, and the problem is solved.

posted:
last update: