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. 将centos 7 自带的 php 5.4升级为 5.6

    1.进入终端后查看php版本 php -v 输出可能如下: PHP 5.4.35 (cli) (built: Nov 14 2014 07:04:10) Copyright (c) 1997-2014 ...

  2. JasperStudio 输出pdf 出错。

    发表于 2008-09-23 09:35:15 楼主net.sf.jasperreports.engine.JRException: Error retrieving field value from ...

  3. hdu3879 最大权闭合图

    若a,b 2点能够相连,那么可以得到ci的价值,也就是说a,b是得到c的前提条件,对于每一个点,又有耗费. 对于本题,先求出最多能够得到的利益有多少,最小割=未被 选的用户的收益之和 + 被选择的站点 ...

  4. PHP实现redis限制单ip、单用户的访问次数功能

    本文实例讲述了PHP实现redis限制单ip.单用户的访问次数功能.分享给大家供大家参考,具体如下: 有时候我们需要限制一个api或页面访问的频率,例如单ip或单用户一分钟之内只能访问多少次 类似于这 ...

  5. C# 获取上传文件的文件名和后缀名

    //获得要上传的文件 HttpPostedFile file = Request.Files[]; //获得到文件名 string fileName = System.IO.Path.GetFileN ...

  6. 集合案例--对ArrayList容器中的内容进行排序

    package com.Set; import java.util.ArrayList; import java.util.Collections; import java.util.Comparat ...

  7. mogodb 修改字段属性

    修改为decimal类型 db.shopgoods.find({'Pricing.Detail':{$type:2}}).forEach(function(x){x.Pricing.Detail=Nu ...

  8. thinkphp5.0 空模块、空控制器、空方法

    空模块 'exception_handle' => function(Exception $e){ // 参数验证错误 if ($e instanceof \think\exception\Va ...

  9. oracle交互命令

    (1)说明:可以替代变量,而该变量在执行时,需要用户输入. sql>select * from emp where job=’&job’; (2)edit  说明:该命令可以编辑指定的s ...

  10. js原生复习2.0

    // 1.闭包的作用// 实现共有变量,函数累加器的实现// 可以做缓存以及储存结构// 可以实现封装,实现属性私有化// 模块开发,防止全局污染// var name = 123;// var in ...