QOJ.ac

QOJ

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

#11130. 奖金分配

统计

最近,最著名的祖伦比亚编程竞赛 Zurumbia Open 在线举行。比赛的总奖金为 $x$ 祖伦比亚卢布!

共有 $n$ 名选手参赛,每名选手的排名从第 1 名到第 $n$ 名不等。没有两名选手的排名相同。

遗憾的是,奖金在选手之间的分配方案尚未公布。目前只知道每名选手都将获得非负整数金额的祖伦比亚卢布,且排名较低的选手获得的奖金不会多于排名较高的选手(即奖金分配序列是非递增的)。

其中一些选手是你的朋友。你决定找出在所有合法的奖金分配方案中,你的朋友们总共必然能获得的奖金的最小值。此外,你还对“最坏情况下的分配”感兴趣——即导致你的朋友们获得的奖金总额最少的分配方案。请编写一个程序来帮助你。

输入格式

第一行包含一个整数 $x$ ($1 \le x \le 10^9$),表示祖伦比亚卢布的总奖金。第二行包含一个长度为 $n$ ($1 \le n \le 400$) 的字符串,仅由大写英文字母 “Y” 和 “N” 组成。如果字符串的第 $i$ 个字符(从 1 开始计数)为 “Y”,则表示排名第 $i$ 的选手是你的朋友,否则为 “N”。

输出格式

输出两行。

第一行必须包含你的朋友们总共必然能获得的奖金的最小值(以祖伦比亚卢布为单位)。

第二行必须包含一个由 $n$ 个非负整数组成的非递增序列,表示在最坏情况下的奖金分配方案中,排名第 1, 2, ..., $n$ 名选手的奖金。这 $n$ 个整数之和必须等于 $x$。如果存在多种最坏情况下的分配方案,你可以输出其中任意一种。

样例

输入 1

23
YNYNNYY

输出 1

10
7 7 3 3 3 0 0

说明

在样例测试用例的分配方案中,排名第 1 的朋友将获得 7 祖伦比亚卢布,排名第 3 的朋友将获得 3 祖伦比亚卢布,另外两名朋友将获得 0 祖伦比亚卢布,因此你的朋友们总共获得了 10 祖伦比亚卢布。可以证明,在任何奖金分配方案中,你的朋友们总共至少会获得 10 祖伦比亚卢布。

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.