Binary Base Basics

 You are given a binary string 

S and an integer K. In one operation, you can pick any bit and flip it, i.e turn 0 to 1 or 1 to 0. Can you make the string S a palindrome using exactly K operations?

Print YES if this is possible, and NO if it is not.

Input Format

  • The first line of input contains one integer T, denoting the number of test cases. The description of T test cases follows.
  • Each test case consists of two lines of input.
    • The first line of each test case contains two space-separated integers N and K, denoting the length of the binary string and the number of operations to be performed.
    • The second line contains the binary string S.

Output Format

For each test case, print the answer on a new line — YES if the S can be made a palindrome using exactly K operations, and NO otherwise.

You may print each character of YES and NO in either uppercase or lowercase (for example, yesyEsYes will all be considered identical).

Constraints

  • 1T1000
  • 1N1000
  • 0KN
  • S is a binary string, i.e, contains only characters 0 and 1

Subtasks

Subtask #1 (100 points): Original constraints

Sample Input 1 

2
3 0
110
6 1
101100

Sample Output 1 

NO
YES

Explanation

Test case 1: S is not a palindrome, and no operations can be performed on it because K=0.

Test case 2: Flip the first bit to obtain S=001100, which is a palindrome.

Previous
Next Post »