B. Assigning to Classestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputReminder: the median of the array [a1,a2,…,a2k+1][a1,a2,…,a2k+1][b1,b2,…,b2k+1][b1,b2,…,b2k+1]bk+1bk+1There are 2n2niiaiaiLet’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 2222What is the minimum possible absolute difference you can achieve?InputEach test contains multiple test cases. The first line contains the number of test cases tt1≤t≤1041≤t≤104The first line of each test case contains a single integer nn1≤n≤1051≤n≤105The second line of each test case contains 2n2na1,a2,…,a2na1,a2,…,a2n1≤ai≤1091≤ai≤109It is guaranteed that the sum of nn105105OutputFor each test case, output a single integer, the minimum possible absolute difference between skill levels of two classes of odd sizes.ExampleinputCopy3
1
1 1
3
6 5 4 1 2 3
5
13 4 20 13 2 5 8 3 17 16
outputCopy0
1
5
NoteIn the first test, there is only one way to partition students — one in each class. The absolute difference of the skill levels will be |1−1|=0|1−1|=0In the second test, one of the possible partitions is to make the first class of students with skill levels [6,4,2][6,4,2]44[5,1,3][5,1,3]33|4−3|=1|4−3|=1Note that you can’t assign like [2,3][2,3][6,5,4,1][6,5,4,1][][][6,5,4,1,2,3][6,5,4,1,2,3][2][2][1,3,4][1,3,4]5566In the third test you can assign the students in the following way: [3,4,13,13,20],[2,5,8,16,17][3,4,13,13,20],[2,5,8,16,17][3,8,17],[2,4,5,13,13,16,20][3,8,17],[2,4,5,13,13,16,20]
B. Assigning to Classes
最新推荐文章于 2024-01-09 18:09:27 发布