#P8343. Minimum Weight Submatrix
Minimum Weight Submatrix
Minimum Weight Submatrix
Given a matrix of dimensions where each cell has a unique cost, you are to determine a non-empty submatrix (i.e. a contiguous rectangular block) that minimizes its weight. For a submatrix with a total price sum , its weight is defined as
where and are given integers. Output the minimum weight possible among all submatrices.
inputFormat
The first line of the input contains four integers , , , and (, ). Each of the next lines contains space-separated integers, representing the price of each cell in the matrix. All prices are distinct and lie within the range .
outputFormat
Output a single integer—the minimum weight, as defined by $$|m - a| + |m - b|,$$ where is the sum of the prices in the chosen submatrix.
sample
1 1 3 5
10
12
</p>