Universal Cup Judging System

Universal Cup

実行時間制限: 3.0 s メモリ制限: 256 MB 満点: 100 ハック可能 ✓
統計

眾所周知,諗出新題目嘅最好方法就係睇錯題意。所以呢度有一道用呢種方式造出嚟嘅題目。

有 $m$ 粒石頭同埋佢哋放入 $n$ 個盒入面嘅 $k$ 種分配方案。每種石頭嘅分配方案都可以表示為一個非負整數數組 $a$,滿足 $a_1 + \dots + a_n = m$。Alice 會構造一種石頭嘅分配方案 $b$,並定義 $\operatorname{cost}(b, a)$ 為將 $a$ 變成 $b$ 所需嘅最少操作次數,操作定義如下:

  • 從裝有正數粒石頭嘅第 $i$ 個盒($1 \le i \le n$)入面攞出 $1$ 粒石頭,放入第 $j$ 個盒($1 \le j \le n$)入面。

佢想搵出一個最優嘅分配方案 $b$,令到 $b$ 去到所有畀定分配方案嘅代價總和最細。

輸入格式

第一行包含 $3$ 個整數 $n, m, k$($1 \le n, k \le 400, 1 \le m \le 10^9$)—— 分別代表盒嘅數量、石頭嘅數量同埋分配方案嘅數量。

接住落嚟嘅 $k$ 行,每行包含 $n$ 個非負整數 $a_{i,j}$($a_{i,1} + \dots + a_{i,n} = m$)—— 代表各個分配方案嘅描述。

輸出格式

輸出一個整數 —— 問題嘅答案。

樣例

樣例輸入 1

5 12 3
3 0 4 1 4
5 2 3 1 1
1 2 3 5 1

樣例輸出 1

8

樣例輸入 2

1 1 2
1
1

樣例輸出 2

0

說明

對於第一個樣例,其中一種可能嘅最優分配方案係 $b = \{3, 2, 3, 2, 2\}$。對於呢個分配方案 $b$,我哋有:

  • 對於 $a = \{3, 0, 4, 1, 4\}$,我哋有 $\operatorname{cost}(b, a) = 3$,因為可以按以下順序進行操作:$\{3, 0, 4, 1, 4\} \to \{3, 1, 4, 1, 3\} \to \{3, 2, 4, 1, 2\} \to \{3, 2, 3, 2, 2\}$。
  • 對於 $a = \{5, 2, 3, 1, 1\}$,我哋有 $\operatorname{cost}(b, a) = 2$,因為可以按以下順序進行操作:$\{5, 2, 3, 1, 1\} \to \{4, 2, 3, 1, 2\} \to \{3, 2, 3, 2, 2\}$。
  • 對於 $a = \{1, 2, 3, 5, 1\}$,我哋有 $\operatorname{cost}(b, a) = 3$,因為可以按以下順序進行操作:$\{1, 2, 3, 5, 1\} \to \{1, 2, 3, 4, 2\} \to \{2, 2, 3, 3, 2\} \to \{3, 2, 3, 2, 2\}$。

因此代價總和係 $8$。可以證明冇辦法得到更細嘅代價總和。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#371EditorialOpen题解jianglyView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.