307046: CF1293A. ConneR and the A.R.C. Markland-N

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

ConneR and the A.R.C. Markland-N

题意翻译

网易云:[削除 - Imprinting](https://music.163.com/#/song?id=30148626) A.R.C. Markland-N有n层。ConneR(真名Colin Neumann)的办公室在第s层。 现在已知除了其中k层以外,每层上都有一个餐厅。请问ConneR的办公室到最近的餐厅有几层的距离? #### 输入格式 多组数据,第一行一个$t$ ( $1\le t\le1000$ )表示数据组数。 每组数据的第一行包含三个正整数,$n$ ( $2\le n\le 10^9$ ),$s$ ( $1\le s\le n$ )和$k$ ( $1\le k\le min(n-1,1000)$ ),分别表示A.R.C. Markland-N的层数,ConneR在哪一层,没有餐厅的楼层的数量。 每组数据的第二行包含k个不同的正整数 $a_1,a_2\dots a_k$ ( $1 \le a_i \le n$ ),表示这些层没有餐厅。 #### 输出格式 共 $t$ 行,每行一个自然数,表示对于每组输入的答案。

题目描述

[Sakuzyo - Imprinting](https://www.youtube.com/watch?v=55Ca6av1kAY) 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!

输入输出格式

输入格式


The first line contains one integer $ t $ ( $ 1 \le t \le 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 \le n \le 10^9 $ , $ 1 \le s \le n $ , $ 1 \le k \le \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 $ a_1, a_2, \ldots, a_k $ ( $ 1 \le a_i \le 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 $ .

输出格式


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.

输入输出样例

输入样例 #1

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

输出样例 #1

2
0
4
0
2

说明

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.

Input

题意翻译

网易云:[削除 - Imprinting](https://music.163.com/#/song?id=30148626) A.R.C. Markland-N有n层。ConneR(真名Colin Neumann)的办公室在第s层。 现在已知除了其中k层以外,每层上都有一个餐厅。请问ConneR的办公室到最近的餐厅有几层的距离? #### 输入格式 多组数据,第一行一个$t$ ( $1\le t\le1000$ )表示数据组数。 每组数据的第一行包含三个正整数,$n$ ( $2\le n\le 10^9$ ),$s$ ( $1\le s\le n$ )和$k$ ( $1\le k\le min(n-1,1000)$ ),分别表示A.R.C. Markland-N的层数,ConneR在哪一层,没有餐厅的楼层的数量。 每组数据的第二行包含k个不同的正整数 $a_1,a_2\dots a_k$ ( $1 \le a_i \le n$ ),表示这些层没有餐厅。 #### 输出格式 共 $t$ 行,每行一个自然数,表示对于每组输入的答案。

加入题单

算法标签: