QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 256 MB 總分: 100

#493. 有趣的纸牌游戏

统计

Andrew 和他的 $k$ 位朋友正在玩一个有趣的纸牌游戏。他们有一副包含 $n$ 张牌的牌堆,每张牌上都有一个整数 $a_i$。Andrew 是发牌员。他的朋友们围坐在他周围,他依次给他们发牌。

Andrew 选择他的其中一位朋友,开始一张接一张地给他发牌。在收到每一张牌后,该玩家可以选择“停(stop)”或者“继续(more)”。如果玩家说“停”,他将不再收到牌,他的得分等于他手中出现次数最多的数值的出现次数。例如,如果玩家收到的牌数值为 $2, 3, 4, 3, 2, 1, 2$ 和 $5$,他的得分是 $3$,因为数值 $2$ 在他的牌中出现了 $3$ 次,且没有其他数值出现次数更多。

接着,Andrew 会选择下一位还没有牌的玩家,并以同样的方式给他发牌。游戏持续进行,直到只剩下一位朋友还没有牌。最后一位玩家将获得剩余所有的牌。

Andrew 的朋友们已经看到了牌堆中牌的排列顺序。现在他们想要选择一种策略,使得所有玩家得分的总和最大。同时,他们希望每位玩家至少能得到一张牌。

请帮助他们制定策略:对于从 $1$ 到 $k-1$ 的每位玩家,找出他在收到哪张牌后应该说“停”。最后一位玩家将获得剩余的牌。

输入格式

输入文件包含多组测试数据。每组测试数据的第一行包含两个整数:$n$ 和 $k$ ($2 \le k \le n \le 10^5, k \le 100$)。第二行包含 $n$ 个整数:牌堆中牌的顺序。牌上的数字绝对值不超过 $10^9$。

最后一行测试数据后跟有一行包含两个零,表示输入结束,无需处理。

输出格式

对于每组测试数据,输出两行。第一行必须包含玩家们能达到的最大得分总和。第二行必须包含给玩家的指令:$k-1$ 个整数 $b_i$。数字 $b_i$ 表示第 $i$ 位玩家应该在收到原始牌堆中的第几张牌后说“停”。每位玩家(包括最后一位)都必须至少收到一张牌。牌在牌堆中按 $1$ 到 $n$ 编号。

样例

输入格式 1

10 2
2 3 2 3 2 1 2 1 2 1
0 0

输出格式 1

6
5

说明

在给出的样例中,第一位玩家将获得牌 $2, 3, 2, 3, 2$,他的得分是 $3$。同样地,第二位玩家获得牌 $1, 2, 1, 2, 1$,他的得分也是 $3$。玩家得分总和为 $6$,这是可能的最大值。

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.