#K93842. Palindromic Subsequence Rearrangement

    ID: 38509 Type: Default 1000ms 256MiB

Palindromic Subsequence Rearrangement

Palindromic Subsequence Rearrangement

You are given a sequence of integers and an integer ( k ). Your task is to determine if it is possible to rearrange the elements of the sequence such that there exists a palindromic subsequence of length ( k ). A sequence is a palindrome if it reads the same forwards and backwards. Note that the subsequence does not need to be contiguous after rearrangement.

More formally, given a sequence ( a_1,a_2,\dots,a_n ) and an integer ( k ), check whether it is possible to rearrange the sequence so that one can select ( k ) elements (not necessarily adjacent) which form a palindrome.

Hint: Think about how the frequency of each number in the sequence affects the possibility to form pairs and (optionally) a center element.

inputFormat

The input is given via standard input (stdin) and consists of multiple test cases. The first line contains an integer ( T ), the number of test cases. Each test case is described as follows:

  • The first line of each test case contains two integers ( n ) and ( k ) --- the length of the sequence and the required length of the palindromic subsequence.
  • The second line contains ( n ) integers ( a_1, a_2, \dots, a_n ) representing the sequence.

It is guaranteed that ( T \ge 1 ).

outputFormat

For each test case, output a single line with either "YES" if it is possible to rearrange the sequence to form a palindromic subsequence of length ( k ), or "NO" otherwise. The output should be written to standard output (stdout).## sample

3
5 3
1 2 1 2 3
6 4
4 4 4 4 4 4
7 5
1 2 3 4 5 6 7
YES

YES NO

</p>