Practice on Toph
Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.
Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.
There are $N$
pigeons standing one after another in a straight line. There are two kinds of pigeons: white pigeon ($\texttt{W}$
) and black pigeon ($\texttt{B}$
). We can represent the ordering of pigeons by string ($S$
). For example, $\texttt{WWB}$
means a white pigeon is standing in the first position, another white pigeon is standing in the second position and a black pigeon is standing in the third position.
Now you are given some extra pigeons, let’s say $\texttt{B}$
black pigeons and $\texttt{W}$
white pigeons. You have to place the extra pigeons in the original string such that the new order will not have any adjacent pigeons with the same color. If it’s possible then print $\texttt{YES}$
, otherwise print $\texttt{NO}$
.
The first line consists of a single Integer T (1 ≤ T ≤ 5) — the number of test cases. For every test cases there will be following four lines:
$N$
($1 ≤ N ≤ 100000$
) representing the number of original pigeons.$W$
($0 ≤ W ≤ 100000$
) representing the number of extra white pigeons.$B$
($0 ≤ B ≤ 100000$
) representing the number of extra black pigeons.For every case print a single line containing either $\texttt{YES}$
or $\texttt{NO}$
as a string.
Input | Output |
---|---|
4 7 BBWBBWW 4 2 2 BB 1 0 2 WW 0 2 5 WWBBB 1 1 | YES YES YES NO |
Explanation of first case: The new series is: WBWBWBWBWBWBW Explanation of second case: The new series is BWB Explanation of third case: The new series is BWBW Explanation of fourth case: There is no way you can place the extra pigeons such that it fulfills the requirement. The bold letters indicate the extra pigeons. |
67% Solution Ratio
bmqubeEarliest,
SaikatSFastest, 0.0s
borderLightest, 262 kB
adnan_tokyShortest, 641B
Login to submit