#C6260. Symmetric Rearrangement
Symmetric Rearrangement
Symmetric Rearrangement
You are given a sequence of integers along with a pivot index. Your task is to determine if it is possible to rearrange the elements of the sequence (except the pivot element) so that the sequence becomes symmetric about the pivot.
A sequence A of length n is said to be symmetric about a pivot index p if the multiset of elements in A[0:p] is equal to the multiset of elements in A[p+1:n]. In mathematical notation, if we define L as the subarray A[0:p] and R as A[p+1:n], then the sequence is symmetric if:
[ \text{multiset}(L) = \text{multiset}(R) ]
Note that the pivot element at index p is excluded from both halves. The pivot index is zero-indexed.
inputFormat
The input is read from standard input and has the following format:
- The first line contains a single integer T (the number of test cases).
- For each test case:
- The first line contains two space-separated integers n and p, where n is the length of the sequence and p is the pivot index (0-indexed).
- The second line contains n space-separated integers representing the sequence.
outputFormat
For each test case, output a single line containing YES
if it is possible to rearrange the sequence to achieve symmetry around the pivot, or NO
otherwise. The output should be written to standard output.
1
5 2
1 2 3 2 1
YES