欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1293A.ConneR and the A.R.C. Markland-N
ConneR and the A.R.C. Markland-N
A.R.C. Markland-N is a tall building with floors numbered from to . Between each two adjacent floors in the building, there is a staircase connecting them.
It's lunchtime for our sensei Colin "ConneR" Neumann Jr, and he's planning for a location to enjoy his meal.
ConneR's office is at floor of the building. On each floor (including floor , of course), there is a restaurant offering meals. However, due to renovations being in progress, of the restaurants are currently closed, and as a result, ConneR can't enjoy his lunch there.
CooneR wants to reach a restaurant as quickly as possible to save time. What is the minimum number of staircases he needs to walk to reach a closest currently open restaurant.
Please answer him quickly, and you might earn his praise and even enjoy the lunch with him in the elegant Neumanns' way!
Input
The first line contains one integer () — the number of test cases in the test. Then the descriptions of test cases follow.
The first line of a test case contains three integers , and (, , ) — respectively the number of floors of A.R.C. Markland-N, the floor where ConneR is in, and the number of closed restaurants.
The second line of a test case contains distinct integers () — the floor numbers of the currently closed restaurants.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case print a single integer — the minimum number of staircases required for ConneR to walk from the floor to a floor with an open restaurant.
Note
In the first example test case, the nearest floor with an open restaurant would be the floor .
In the second example test case, the floor with ConneR's office still has an open restaurant, so Sensei won't have to go anywhere.
In the third example test case, the closest open restaurant is on the -th floor.
Samples
5
5 2 3
1 2 3
4 3 3
4 1 2
10 2 6
1 2 3 4 5 7
2 1 1
2
100 76 8
76 75 36 67 41 74 10 77
2
0
4
0
2
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |