[Solution] Nahaane Jaa CodeChef Solution
Problem
"Bapuji - Ae Jethiya Nahaane Jaa Nahaane Jaa".
Bapuji is furious with Jethiya because he did not bathe before eating. Jethiya does not want to bathe right now, but in order to do so, he must first establish his innocence to Bapuji.
Bapuji gives Jethiya a problem, and if Jethiya solves it, Bapuji will allow him to eat his food before taking a bath. Jethiya asks for your help to solve the problem.
You are given an array of size and an integer . You can perform the following operation on the given array any number of times (possibly zero):
- Choose two integers and ()
- Then, for each such that , set to . Here, denotes the floor function.
- That is, apply the following to the subarray :
- If this subarray has odd length, set all its elements to be equal to the middle element.
- If it has even length, set all its elements to be equal to the left one among the two middle elements.
For example, if then:
- If we choose and , the array will change as follows:
- If we choose and , the array will change as follows:
Is it possible to make all the array elements equal to after performing some number of operations?
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains two space-separated integers and — the number of elements in the array and the value respectively.
- The second line of each test case contains space-separated integers — the elements of the array.
Output Format
For each test case, output on a new line the answer: Yes
if all the elements can be made equal to , and No
otherwise.
Each letter of the output may be printed in either uppercase or lowercase, i.e, Yes
, YES
, and yEs
will all be treated as equivalent.
Explanation:
Test case : There is no way to make all the elements of the array equal .
Test case : One way of performing operations is as follows:
- First, choose and . This makes the array .
- Then, choose and . This makes the array , and we are done.
Test case : Choose and . The middle element is so everything becomes , as required.
Test case : There is no way to make everything equal to .
No comments:
Post a Comment