D. Green and black tea
Time limit per test
1 second
Memory limit per test
256 Megabytes
Input
Standard input
Output
Standard output
Innokentiy likes tea is very much more and today he wants to drink exactly n cups. He would is happy to drink the but he had exactly n tea bags, a of them are green and B are black.
Innokentiy doesn ' t like to drink's same tea (green or black) is more than k times in a row. Your task is to determine "order of brewing tea bags so" innokentiy'll be able to drink n cups of tea, without Dr Inking 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 "I" 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 T Ea. It is guaranteed that a + b = N.
Output
If it is impossible to drink n cups the 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 to be green. If some character equals ' B ', then the corresponding cup of tea should is 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
Just start by filling the array with the most ~ character ~ and then inserting another character into it in turn.
AC Code:
#include <bits/stdc++.h>
using namespace std;
int main ()
{
int n,k,a,b;
Char b = ' B ', g = ' g ';
scanf ('%d%d%d%d ', &n,&k,&a,&b);
if (a > B) swap (A,B), swap (b,g);
String St (n,b);
for (int i = k; i < N; i = = k + 1) {
if (a = = 0) {
printf ("no\n");
return 0;
}
St[i] = G;
a--;
}
for (int i = 0; i < N && a > 0; i++) {
if (st[i] = G | | (i > 0 && st[i-1] = = G) | | (i + 1 < N && St[i + 1] = = G)) Continue;
St[i] = G;
a--;
}
cout << St;
return 0;
}