Showmatch
In a showmatch for a computer game, 2n esports players are set to participate; the rating of the i-th player is ai. The ratings of all players are distinct.
For each player, the most exciting match will be with the player whose rating is the closest to theirs. Formally, for the i-th player, the best opponent is another player j such that the absolute difference in their ratings |ai−aj| is minimized among all ways to choose player j. Note that some player can have more than one best opponent.
For example, if there are 4 esports players with ratings [3,7,5,12], then:
- for player 1, the best opponent is player 3;
- for player 2, the best opponent is player 3;
- for player 3, the best opponents are players 1 and 2;
- for player 4, the best opponent is player 2.
The organizers of the showmatch want to pair the participants so that each player is in exactly one pair, and in each pair, the players are best opponents for each other. Determine whether such a pairing exists.
Input
The first line contains a single integer t (1≤t≤100) — the number of test cases.
Each test case consists of two lines:
- the first line contains a single integer n (2≤n≤50);
- the second line contains 2n integers a1,a2,…,a2n (1≤ai≤105; all ai are distinct).
Output
For each test case, if it is possible to pair the participants such that in each pair the participants are best opponents for each other, output YES. Otherwise, output NO.
Note
In the first example, pairing is impossible. For instance, if we form pairs (1,3) and (2,4), participant 4 will not be the best opponent for participant 2.
In the second example, it is possible to pair the participants as (1,3) and (2,4).
3 2 3 7 5 12 2 3 7 5 8 2 3 7 5 9
NO YES YES
Discussions & Comments
Share your approach or ask questions about this problem (0)
You must be logged in to comment or start a discussion on this problem.
Log InNo comments yet. Be the first to comment!
Actions
Open on CodeforcesAbout Platform
Problem Discussions
0Have questions or want to share your solution approach? Join the discussion.
View / write comments