Reminder: the median of the array [a1,a2,…,a2k+1][a1,a2,…,a2k+1] of odd number of elements is defined as follows: let [b1,b2,…,b2k+1][b1,b2,…,b2k+1] be the elements of the array in the sorted order. Then median of this array is equal to bk+1bk+1.

There are 2n2n students, the ii-th student has skill level aiai. 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 22 classes such that each class has odd number of students (not divisible by 22). 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?

Input
Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041≤t≤104). The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤1051≤n≤105) — the number of students halved.

The second line of each test case contains 2n2n integers a1,a2,…,a2na1,a2,…,a2n (1≤ai≤1091≤ai≤109) — skill levels of students.

It is guaranteed that the sum of nn over all test cases does not exceed 105105.

Output
For each test case, output a single integer, the minimum possible absolute difference between skill levels of two classes of odd sizes.

Example
Input
3
1
1 1
3
6 5 4 1 2 3
5
13 4 20 13 2 5 8 3 17 16
Output
0
1
5
Note
In 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|=0.

In 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], so that the skill level of the first class will be 44, and second with [5,1,3][5,1,3], so that the skill level of the second class will be 33. Absolute difference will be |4−3|=1|4−3|=1.

Note that you can’t assign like [2,3][2,3], [6,5,4,1][6,5,4,1] or [][], [6,5,4,1,2,3][6,5,4,1,2,3] because classes have even number of students.

[2][2], [1,3,4][1,3,4] is also not possible because students with skills 55 and 66 aren’t assigned to a class.

In 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] or [3,8,17],[2,4,5,13,13,16,20][3,8,17],[2,4,5,13,13,16,20]. Both divisions give minimal possible absolute difference.
排序后找中间的那两个数字就可以了。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;const int maxx=2e5+100;
int a[maxx];
int n;int main()
{int t;scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=1;i<=2*n;i++) cin>>a[i];sort(a+1,a+1+2*n);cout<<abs(a[n]-a[n+1])<<endl;}return 0;
}

努力加油a啊,(o)/~

Assigning to Classes CodeForces - 1300B相关推荐

  1. Codeforces Round #618 (Div. 2)-B. Assigning to Classes

    Reminder: the median of the array [a1,a2,-,a2k+1] of odd number of elements is defined as follows: l ...

  2. 贪心 ---- Codeforces Round #618 (Div. 2)B. Assigning to Classes+贪心[证明过程]

    题目链接 题目大意:给你2∗n2*n2∗n个数,将这些数分成2个集合使得两个集合中位数的差值最小 解题思路:我懵了一个结论就是排序之后取中间的两个数然后就ac了 我们先对这些数字从小到大排序 证明:1 ...

  3. B. Assigning to Classes

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  4. CF 1300.B——Assigning to Classes【思维】

    题目传送门 Reminder: the median of the array [a1,a2,-,a2k+1][a1,a2,-,a_{2k+1}][a1,a2,-,a2k+1​] of odd num ...

  5. jquery创建a_如何使用jQuery创建游戏

    jquery创建a How to create a game using jQuery Today we are making a simple puzzle game called "Fi ...

  6. Codeforces Round #404 (Div. 2) B. Anton and Classes 水题

    B. Anton and Classes 题目连接: http://codeforces.com/contest/785/problem/B Description Anton likes to pl ...

  7. codeforces div2 Not Assigning 题解

    codeforces div2 Not Assigning 题解 原题链接 /* 题意:构造一棵素数树.素数树定义如下: 这颗树中任意一条边 or 任意两条边 权重之和为素数,每条边的权重自己分配. ...

  8. Codeforces Round #766 (Div. 2)C. Not Assigning

    C. Not Assigning 题意:给出n个节点,n-1条路经,给每条路径赋上初值(这里的值必须为素数),使得每两条路径权值之和为素数,且对于每条路径,每个节点只能访问一次(即判断是否为线性结构) ...

  9. Educational Codeforces Round 10 A. Gabriel and Caterpillar 模拟

    A. Gabriel and Caterpillar 题目连接: http://www.codeforces.com/contest/652/problem/A Description The 9-t ...

最新文章

  1. 【性能优化】纳尼?内存又溢出了?!是时候总结一波了!!
  2. 冰点文库下载器停止工作解决办法
  3. python处理数据的优势-Python的优势及应用领域
  4. C++中引用和指针的不同
  5. gartner android 市场份额,Gartner:Android去年市场份额超iOS和RIM
  6. Linux学习参考书
  7. windows聚焦图片为什么不更新了_为什么年轻明星都不愿意接周星驰的戏? 林更新道出了事情的真相|周星驰|林更新|喜剧之王|演员...
  8. java中this_夯实Java基础系列7:一文读懂Java 代码块和执行顺序
  9. python怎么写测试脚本语言_用python编写测试脚本
  10. ubuntu下查看apache的日志
  11. ExtAspNet v3.1.9
  12. 查看Android设备的分辨率
  13. 使用高斯金字塔和拉普拉斯金字塔重构图像(matlab代码)
  14. 数乌龟(母牛,兔子....)[打表法]
  15. WPS Android版API
  16. android自动悬浮窗代码,三行代码实现Android应用内悬浮窗,无需一切权限,适配所有ROM和厂商...
  17. 视频教程-opencv应用实例-实战视频教学-计算机视觉
  18. 2022-2028全球英语口语练习平台行业调研及趋势分析报告
  19. Flask_从入门到放弃?不!!!从入门到入土!!
  20. 最近发现的一个学习宝库

热门文章

  1. Upload-labs闯关
  2. 中山市区电信5g覆盖地图_2020中山数字经济发展论坛举行,上线工业互联网平台...
  3. sql数据类型转换oracle,ORACLE SQL数据类型转换
  4. django 打开的html css_Django分页完整示例
  5. js input点击事件_Vue.js的旅程,简单的todo实例「602」
  6. log4cplus导致主进程不能退出问题解决
  7. Android开发之EditText输入显示文字hint大小设置
  8. ubuntu16下vue-cli安装
  9. Activity的task相关
  10. ios文件系统架构图,图片解说