#C9866. Taco Rearrangement Challenge
Taco Rearrangement Challenge
Taco Rearrangement Challenge
You are given a set of chess pieces represented by a string of characters. Each character represents a type of piece: 'Q' for Queen, 'B' for Bishop, and 'R' for Rook. The number of pieces is given by an integer n. Your task is to determine if it is possible to rearrange exactly k pieces such that no two pieces attack each other on an infinite chessboard.
Under the assumed conditions, it is always possible to rearrange k pieces into a non-attacking configuration provided that k ( \leq ) n. Otherwise, if k > n, the task is impossible. Output "YES" if ( k \leq n ), and "NO" otherwise.
Note: The problem uses standard input and output. All equations and mathematical conditions are expressed in ( \LaTeX ) format where applicable.
inputFormat
The input is given via standard input in the following format:
Line 1: An integer (n) representing the total number of pieces. Line 2: An integer (k) indicating the exact number of pieces to rearrange. Line 3: A string of length (n) consisting of the characters 'Q', 'B', and 'R'.
outputFormat
Output a single line to standard output containing "YES" if it is possible to rearrange exactly (k) pieces into a non-attacking configuration; otherwise, output "NO".## sample
5
3
QQBRB
YES