Universal Cup Judging System

Universal Cup

时间限制: 3.0 s 内存限制: 256 MB 总分: 100 可 Hack ✓
统计

아시다시피 새로운 문제를 만들어내는 가장 좋은 방법은 문제 지문을 잘못 읽는 것입니다. 여기 그런 방식으로 만들어진 문제가 하나 있습니다.

$m$개의 돌과 이를 $n$개의 상자에 나누어 담는 $k$개의 분배 상태가 있습니다. 각 돌의 분배 상태는 $a_1 + \dots + a_n = m$을 만족하는 음이 아닌 정수 배열 $a$로 나타낼 수 있습니다. Alice는 돌의 분배 상태 $b$를 하나 구성하고, $a$를 $b$와 같게 만들기 위해 필요한 아래 연산의 최소 횟수를 $\operatorname{cost}(b, a)$로 정의합니다:

  • 돌이 양수 개만큼 들어 있는 상자 $i$ ($1 \le i \le n$)에서 돌 $1$개를 꺼내어 상자 $j$ ($1 \le j \le n$)에 넣습니다.

그녀는 최적의 분배 상태 $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.