A.R.C. Markland-N is a tall building with n floors numbered from 1 to n. 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 s of the building. On each floor (including floor s, of course), there is a restaurant offering meals. However, due to renovations being in progress, k 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 t (1≤t≤1000) — the number of test cases in the test. Then the descriptions of t test cases follow.

The first line of a test case contains three integers n, s and k (2≤n≤10^9, 1≤s≤n, 1≤k≤min(n−1,1000)) — 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 k distinct integers a1,a2,…,ak (1≤ai≤n) — the floor numbers of the currently closed restaurants.

It is guaranteed that the sum of k over all test cases does not exceed 1000.

Output
For each test case print a single integer — the minimum number of staircases required for ConneR to walk from the floor s to a floor with an open restaurant.

Example

input
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
output
2
0
4
0
2

Note
In the first example test case, the nearest floor with an open restaurant would be the floor 4.

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 6-th floor.

#include<bits/stdc++.h>using namespace std;
int t, n, s, k;int main() {cin >> t;while (t--) {map<int, int> mp;scanf("%d%d%d",&n,&s,&k);int x;for (int i = 1; i <= k; i++) {scanf("%d", &x);mp[x] = 1;}for (int i = 0; i <= n; i++)if ((!mp[s - i]&&s-i>=1) || (!mp[s + i]&&s+i<=n)) {printf("%d\n", i);break;}}return 0;}

A ConneR and the A.R.C. Markland-N相关推荐

  1. ConneR and the A.R.C. Markland-N CodeForces - 1293A(暴力)

    Sakuzyo - Imprinting A.R.C. Markland-N is a tall building with n floors numbered from 1 to n. Betwee ...

  2. 基础算法 —— 模拟思维

    [概述] 模拟,是根据实际问题建立模型,模拟实际按程序走一遍,最终求出答案. 思维,则是与逻辑思维有关,其需要针对题意.数据范围等抽丝剥茧抽离出有用的信息,从而得出一个结果. 对于一般的模拟,直接根据 ...

  3. 秀一下以前搜房soufun发贴机的发帖群发日志!!呵呵..

    秀一下以前搜房soufun论坛发贴机的发帖群发日志!!呵呵.. QQ 1163551688 "2009-11-28 18:00:06 562","qwerty00789& ...

  4. 硬盘的S.M.A.R.T.是什么?如何看懂它

    说道硬盘的S.M.A.R.T.这个既常用然而又陌生的家伙,说真的如果直接看的话有多少个人能看懂这份表?现在我们就要简单的讲解一下NVMe SSD的S.M.A.R.T.信息. 说道硬盘的S.M.A.R. ...

  5. S.M.A.R.T.

    S.M.A.R.T.,全称为"Self-Monitoring Analysis and Reporting Technology",即"自我监测.分析及报告技术" ...

  6. 给定一个 n X n 的矩阵 和 R,求旋转 90 X R 度以后的矩阵

    1. 问题 [例题]循环输入,每组数据先输入一个 n(n<=10),然后 n 行 n 列数据代表一个矩阵, 每个数据为一个整数,然后再给出一个数字 R,输出这个矩阵按照顺时针旋转 90 X R ...

  7. python二进制打开(rb)和文本格式打开(r)什么区别?

    使用 open() 函数以文本格式打开文件和以二进制格式打开文件,唯一的区别是对文件中换行符的处理不同. 在 Windows 系统中,文件中用 "\r\n" 作为行末标识符(即换行 ...

  8. \r \r\n \t的区别

    \n 软回车:       在Windows 中表示换行且回到下一行的最开始位置.相当于Mac OS 里的 \r 的效果.       在Linux.unix 中只表示换行,但不会回到下一行的开始位置 ...

  9. adb install -r ,-d 等的解释

    adb install -r 替换已存在的应用程序,也就是说强制安装 adb install -l 锁定该应用程序 adb install -t 允许测试包 adb install -s 把应用程序安 ...

  10. Android Studio – Cannot resolve symbol ‘R’

    Android Studio – Cannot resolve symbol 'R' 解决方法: Build -> Clean Project Tools -> Android -> ...

最新文章

  1. ADS下C语言中局部变量的存储位置分配
  2. 前端模块化(一):模块化那些事儿
  3. 存储新技术之“连续数据保护(CDP)”
  4. 负载均衡SLB新功能介绍
  5. 跟我极速尝鲜 Spring Boot 2.3
  6. Nginx配置性能优化的方法
  7. HashSet原理、TreeSet
  8. odb对象关系映射系统
  9. js怎么获取ueditor值_js获取UEditor富文本编辑器中的图片地址
  10. Visa在全球范围内增加对女足的投入
  11. 笔记本和打印机不在一个网段,无线连接打印机的方法
  12. 电脑怎么打出冒号符号_冒号的用法有哪些?写作文的时候冒号怎么用?冒号在电脑上怎么打出来?...
  13. Docker 图片水印中文乱码显示为方框, 设置Docker容器字体
  14. Kotlin 注解全解析
  15. php代码审计之chinaz小试牛刀
  16. 可视化的Keil工程配置模板,一招提高单片机开发效率
  17. LinkPdf转换器-PDF转换成Word使用教程
  18. mybatis开启二级缓存
  19. windows 2003 自带tftp32设置方法
  20. java中将两数组拼接为一个数组

热门文章

  1. PHP 运行后出现The requested URL was not found on this server.
  2. java计算机毕业设计绿洲小区快递配送系统源代码+数据库+系统+lw文档
  3. 三甲川荧光染料Cy3DIGE NHS ester,Cy3DIGE琥珀酰亚胺活化酯,Cyanine3DIGE 活化酯,Ex:555nmEm:569nm
  4. 人工智能--黑白图片上色
  5. vue调用手机扫描二维码
  6. Mac outlook设置HTML,设置苹果MAC 端outlook客户端说明
  7. [unity] unity学习——弹球游戏
  8. 数控弯管机xyz转换ybc的算法_一种弯管数控数模到CAD数模转换的方法与流程
  9. 中国有句俗语叫“三天打鱼两天晒网”。某人从1990年1月1日起开始“三天打鱼两天晒网”, 问这个人在以后的某一天中是“打鱼”还是“晒网”?(考虑中间有几个闰年)
  10. STM32CubeMX安装(全图文安装步骤,一步不落下)