QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#9273. 石头游戏

Statistics

Porfiry 和 Rodion 正在玩石头游戏。他们有 $m$ 颗石头和 $n$ 个排成一行的盒子。他们考虑将所有石头放入盒子的不同分布方式。每种分布都可以用 $n$ 个非负整数 $a_1, a_2, \dots, a_n$ 来描述,满足 $a_1 + a_2 + \dots + a_n = m$。

Rodion 喜欢将石头从一个盒子移动到相邻的盒子。在一步操作中,他可以从某个非空盒子中取出恰好一颗石头,并将其放入相邻的盒子中。对于两种分布 $a = (a_i)$ 和 $b = (b_i)$,Porfiry 定义 $W(a, b)$ 为将分布 $a$ 转换为分布 $b$ 所需的最少移动次数。

经过观察,Porfiry 给 Rodion 布置了以下任务:给定 $k$ 种分布 $(a^1_i), (a^2_i), \dots, (a^k_i)$,求出一个分布 $b$,使得总距离 $W(a^1, b) + W(a^2, b) + \dots + W(a^k, b)$ 达到最小。

输入格式

第一行包含三个空格分隔的整数 $n, m$ 和 $k$ ($1 \le n, k \le 1000, 1 \le m \le 10^9$)。

接下来的 $k$ 行中,第 $j$ 行包含第 $j$ 种分布的描述,由 $n$ 个非负整数 $a^j_1, a^j_2, \dots, a^j_n$ 表示 ($a^j_1 + a^j_2 + \dots + a^j_n = m$)。

输出格式

输出最优分布 $b$。如果存在多个最优解,输出其中任意一个即可。

样例

样例输入 1

4 10 3
1 2 3 4
4 2 1 3
1 3 4 2

样例输出 1

1 3 3 3

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.