P4194 Matrix

Description

Given an integer matrix $A[n\times m]$, find a matrix $B[n\times m]$ such that $\forall 1\le i\le n,1\le j\le m,B_{i,j}\in[L,R]$, and minimize the following value. $$\max\begin{cases}\displaystyle\max_{1\le j\le m}\left\{\left|\sum_{i=1}^n\left(A_{i,j}-B_{i,j}\right)\right|\right\}\\\displaystyle\max_{1\le i\le n}\left\{\left|\sum_{j=1}^m\left(A_{i,j}-B_{i,j}\right)\right|\right\}\end{cases}$$

Input Format

The first line contains two integers $n$ and $m$, the size of the matrix. Each of the next $n$ lines contains $m$ integers, describing matrix $A$. The last line contains two integers $L$ and $R$.

Output Format

Output one line with a single integer representing the answer.

Explanation/Hint

Constraints: For 100% of the testdata, $n, m \le 200$, $0 \le L \le R \le 1000$, $0 \le A_{i,j} \le 1000$. Translated by ChatGPT 5