CF746D.Green and Black Tea

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Innokentiy likes tea very much and today he wants to drink exactly n cups of tea. He would be happy to drink more but he had exactly n tea bags, a of them are green and b are black.

Innokentiy doesn't like to drink the same tea (green or black) more than k times in a row. Your task is to determine the order of brewing tea bags so that Innokentiy will be able to drink n cups of tea, without drinking the same tea more than k times in a row, or to inform that it is impossible. Each tea bag has to be used exactly once.

伊诺肯季非常喜欢喝茶,今天他想恰好喝 nn 杯茶。他本来还想多喝一些,但手头恰好只有 nn 个茶包,其中 aa 个是绿茶包,bb 个是红茶包。

伊诺肯季不喜欢连续喝同一种茶(绿茶或红茶)超过 kk 次。你的任务是确定一种泡茶包的顺序,使得伊诺肯季能够恰好喝完 nn 杯茶,且不出现同一种茶连续饮用超过 kk 次的情况;如果不可能实现,则需说明这一点。每个茶包必须且仅能使用一次。

输入格式

The first line contains four integers n, k, a and b (1 ≤ k ≤ n ≤ 105, 0 ≤ a, b ≤ n) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed that a + b = n.

第一行包含四个整数 nn、kk、aa 和 bb(1 ≤ k ≤ n ≤ 1051 \le k \le n \le 10^5,0 ≤ a, b ≤ n0 \le a,\,b \le n)——分别表示伊诺肯季想要喝的茶杯数、他连续喝同一种茶的最大杯数、绿茶包和红茶包的数量。保证 a + b = na + b = n。

输出格式

If it is impossible to drink n cups of tea, print "NO" (without quotes).

Otherwise, print the string of the length n, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be black.

If there are multiple answers, print any of them.

如果无法喝下 nn 杯茶,则输出 "NO"(不带引号)。

否则,输出一个长度为 nn 的字符串,该字符串仅由字符 'G' 和 'B' 组成。若某个字符为 'G',则对应的那杯茶应为绿茶;若某个字符为 'B',则对应的那杯茶应为红茶。

若存在多个合法答案,输出任意一个即可。

输入输出样例

  • 输入#1

    5 1 3 2

    输出#1

    GBGBG
  • 输入#2

    7 2 2 5

    输出#2

    BBGBGBB
  • 输入#3

    4 3 4 0

    输出#3

    NO

输入解题思路,AI测评打分。不知道怎么写?

首页