トヨタ自動車プログラミングコンテスト2023#1(AtCoder Beginner Contest 298)
G
Strawberry War
AtCoder
⌀ 2405
原题
← Ex→
翻译中…

Problem Statement

翻译中…

We have a rectangular cake. It is partitioned into $H$ rows and $W$ columns of sections, and the section at the $i$-th row from the top and $j$-th column from the left has $s_{i,j}$ strawberries on it.

翻译中…

You will make $T$ cuts to divide the cake into $T+1$ pieces. Each cut will be done in one of the following two manners.

翻译中…
  • Choose an existing piece with two or more rows of sections. Additionally, choose two adjacent rows from that piece, and cut the piece along the boundary between them to divide it into two smaller pieces.
  • Choose an existing piece with two or more columns of sections. Additionally, choose two adjacent columns from that piece, and cut the piece along the boundary between them to divide it into two smaller pieces.
翻译中…

You want to distribute the strawberries onto the resulting pieces as evenly as possible. Let $x_1,x_2,\ldots,x_{T+1}$ be the numbers of strawberries on the resulting $T+1$ pieces, and $M$ and $m$ be the maximum and minimum among those numbers, respectively. Find the minimum possible value of $M-m$.

翻译中…

Constraints

翻译中…
  • $1 \leq H,W \leq 6$
  • $1 \leq T \leq HW-1$
  • $0 \leq s_{i,j} \leq 10^{16}$
  • All values in the input are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

H W T
s_{1,1} \ldots s_{1,W}
\vdots
s_{H,1} \ldots s_{H,W}

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
2 3 4
2 3 4
4 1 3
Output #1
2
The figure below shows a way to cut the cake so that the top-left, bottom-left, middle, top-right, and bottom-right pieces have $2$, $4$, $4$, $4$, and $3$ strawberries on them, respectively. Here, the difference between the maximum and minimum number of strawberries is $4-2=2$. It is impossible to achieve a smaller difference, so the answer is $2$. ![image](https://img.atcoder.jp/abc298/6d6a4c5fc7ac2723af8e8b30e48957da.png)
Input #2
2 2 3
0 0
0 0
Output #2
0
题目信息
题号
abc298_g
时间限制
6 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。