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

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Sakuzyo - Imprinting

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

The first line of a test case contains three integers nn , ss and kk ( 2n1092 \le n \le 10^9 , 1sn1 \le s \le n , 1kmin(n1,1000)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 kk distinct integers a1,a2,,aka_1, a_2, \ldots, a_k ( 1ain1 \le a_i \le n ) — the floor numbers of the currently closed restaurants.

It is guaranteed that the sum of kk over all test cases does not exceed 10001000 .

输出格式

For each test case print a single integer — the minimum number of staircases required for ConneR to walk from the floor ss 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 44 .

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

首页