307093: CF1300B. Assigning to Classes
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Assigning to Classes
题意翻译
- 给定一个有 $2\times n$ 个数的数列。 - 让你把它分成两组,使得每一组的数量均为奇数。 - 请你求出两组中位数之差的绝对值的最小值。 - translate by @[ShineEternal](https://www.luogu.com.cn/user/45475)。题目描述
Reminder: the [median](https://en.wikipedia.org/wiki/Median) of the array $ [a_1, a_2, \dots, a_{2k+1}] $ of odd number of elements is defined as follows: let $ [b_1, b_2, \dots, b_{2k+1}] $ be the elements of the array in the sorted order. Then median of this array is equal to $ b_{k+1} $ . There are $ 2n $ students, the $ i $ -th student has skill level $ a_i $ . It's not guaranteed that all skill levels are distinct. Let's define skill level of a class as the median of skill levels of students of the class. As a principal of the school, you would like to assign each student to one of the $ 2 $ classes such that each class has odd number of students (not divisible by $ 2 $ ). The number of students in the classes may be equal or different, by your choice. Every student has to be assigned to exactly one class. Among such partitions, you want to choose one in which the absolute difference between skill levels of the classes is minimized. What is the minimum possible absolute difference you can achieve?输入输出格式
输入格式
Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 10^4 $ ). The description of the test cases follows. The first line of each test case contains a single integer $ n $ ( $ 1 \le n \le 10^5 $ ) — the number of students halved. The second line of each test case contains $ 2n $ integers $ a_1, a_2, \dots, a_{2 n} $ ( $ 1 \le a_i \le 10^9 $ ) — skill levels of students. It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 10^5 $ .
输出格式
For each test case, output a single integer, the minimum possible absolute difference between skill levels of two classes of odd sizes.
输入输出样例
输入样例 #1
3
1
1 1
3
6 5 4 1 2 3
5
13 4 20 13 2 5 8 3 17 16
输出样例 #1
0
1
5