欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2149B.Unconventional Pairs
Unconventional Pairs
A popular reality show Unconventional Pairs has been launched in the city. According to the rules of the show, participants are paired in an unusual way: with an even number of people, all participants must be in pairs.
Petya has an array of integers . It is known that is even. Petya must divide the participants (numbers) into exactly pairs $(a_{p_1},a_{q_1}),\,(a_{p_2},a_{q_2}),\dots\,(a_{p_\frac{n}{2}},a_{q_\frac{n}{2}})$. Each index can be included in no more than one pair.
For a pair , its difference is defined as . Petya wants to form unconventional pairs such that the maximum difference among all pairs is minimized.
Determine the minimum possible value of this maximum difference.
Input
Each test consists of several test cases.
The first line contains a single integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains one even number () — the length of the array .
The second line contains integers — the elements of the array .
It is guaranteed that the sum of the values of across all test cases does not exceed .
Output
For each test case, output a single number — the minimum possible maximum difference between the elements in pairs.
Note
In the first test case, the array is: . The only possible (and therefore optimal) pair is , its difference is , the answer is .
In the second test case, the array is: . We can choose pairs — and : both differences are equal to , therefore, the maximum difference is .
In the third test case, the array is: . We can choose pairs: , , . The differences are: — the largest is .
Samples
5
2
1 2
4
10 1 2 9
6
3 8 9 3 3 2
8
5 5 5 5 5 5 5 5
4
-5 -1 2 6
1
1
1
0
4
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |