time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output

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.

Input

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.

Output

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.

Examples

input

5 1 3 2

output

GBGBG

input

7 2 2 5

output

BBGBGBB

input

4 3 4 0

output

NO

【题目链接】:http://codeforces.com/contest/746/problem/D

【题解】



最后必然是分成a/k 个绿茶块,b/k个黑茶块;

如果a/k==b/k

显然可以交替出现;

如果a/k>b/k

则先放k个a,然后放一个b;

这样a-=k,b-=1;

则a/k会越来越逼近b/k;

最后交替出现就可以了。

balabala



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; //const int MAXN = x;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0); int n,k,a,b;
char t[2];
string ans = ""; int main()
{
//freopen("F:\\rush.txt","r",stdin);
rei(n);rei(k);rei(a);rei(b);
t[0]='G',t[1] = 'B';
if (a < b)
swap(a,b),swap(t[0],t[1]);
bool ok = false;
while ( (a/k)>(b/k))
{
if (a<k || b<1)
break;
rep1(i,1,k)
ans+=t[0];
ans+=t[1];
a-=k;
b--;
}
while (a>0 && b>0)
{
int ma = min(a,k);
rep1(i,1,ma)
ans+=t[0];
a-=ma;
ma = min(b,k);
rep1(i,1,ma)
ans+=t[1];
b-=ma;
}
if (a>k)
{
puts("NO");
return 0;
}
rep1(i,1,a)
ans+=t[0];
if (b>k)
{
puts("NO");
return 0;
}
rep1(i,1,b)
ans+=t[1];
cout << ans << endl;
return 0;
}

【21.58%】【codeforces 746D】Green and Black Tea的更多相关文章

  1. Codeforces 746D:Green and Black Tea(乱搞)

    http://codeforces.com/contest/746/problem/D 题意:有n杯茶,a杯绿茶,b杯红茶,问怎么摆放才可以让不超过k杯茶连续摆放,如果不能就输出NO. 思路:首先,设 ...

  2. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  3. 【21.37%】【codeforces 579D】"Or" Game

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【21.21%】【codeforces round 382D】Taxes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【58.33%】【codeforces 747B】Mammoth's Genome Decoding

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【codeforces 757D】Felicity's Big Secret Revealed

    [题目链接]:http://codeforces.com/problemset/problem/757/D [题意] 给你一个01串; 让你分割这个01串; 要求2切..n+1切; 对于每一种切法 所 ...

  7. 【codeforces 757E】Bash Plays with Functions

    [题目链接]:http://codeforces.com/problemset/problem/757/E [题意] 给你q个询问; 每个询问包含r和n; 让你输出f[r][n]; 这里f[0][n] ...

  8. 【77.78%】【codeforces 625C】K-special Tables

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  9. 【30.23%】【codeforces 552C】Vanya and Scales

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. 【JZOJ4910】【NOIP2017模拟12.3】子串

    题目描述 数据范围 =w= 暴力: 从前往后枚举一个i,再从前往后枚举一个j: 如果s[i]不是s[j]的子串,更新答案,继续枚举: 如果s[i]是s[j]的子串,停止枚举. 因为对于s[k] (k& ...

  2. H5视频播放自动全屏,暂停退出全屏等功能

    html5视频播放自动全屏,暂停退出全屏等功能 在参考了html5 video fullScreen全屏实现方式及司徒正美的书<javascript框架设计>287页相关代码后,在Safa ...

  3. PHP Laravel系列之环境搭建( VirtualBox+Vagrant+Homestead+系列网址)

    搭建环境从来都是阻挡一门新技能的最致命的硬伤,为了这个环境,我又是花费了半天的时间,各种问题层出不穷,下面基于网上的一些教程(我看到的都多少有些问题) 开始的时候是在实验楼这个平台上开始学习的,不过 ...

  4. iOS小技巧:用runtime 解决UIButton 重复点击问题

    http://www.cocoachina.com/ios/20150911/13260.html 作者:uxyheaven 授权本站转载. 什么是这个问题 我们的按钮是点击一次响应一次, 即使频繁的 ...

  5. Redis 设置密码登录

    前言 redis在生产环境中通常都会设置密码以保证一定的安全性,本篇blog就简单记录一下如何在redis中设置客户端登录密码. 修改redis.conf RT,打开redis.conf文件,搜索re ...

  6. jmeter响应代码为乱码

    1.在请求的前面添加BeanShell PostProcessor 输入prev.setDataEncoding("UTF-8"); 2.当响应数据或响应页面没有设置编码时,jme ...

  7. 2019-1-29-Moq基础-判断方法被执行

    title author date CreateTime categories Moq基础 判断方法被执行 lindexi 2019-01-29 16:29:57 +0800 2019-01-17 1 ...

  8. MapReduce数据流-概述

  9. Datanodes-心跳机制

  10. AtCoder Beginner Contest 078 D ABS

    光做C了,做完C,就要结束了,看了看D,没看懂那操作啥意思,就扔了. 刚才看了看,突然懂了.. 就是每个人从那堆牌上边拿牌,最少拿一张,最多可以全拿走,然后手里留下最后一张拿到的,其余的都扔掉. 比如 ...