codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1293A.md (2449B)


      1 Source: https://codeforces.com/problemset/problem/1293/A
      2 
      3 A. ConneR and the A.R.C. Markland-N
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 [Sakuzyo - Imprinting](https://www.youtube.com/watch?v=55Ca6av1kAY)
     22 
     23 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.
     24 
     25 It's lunchtime for our sensei Colin "ConneR" Neumann Jr, and he's planning for a location to enjoy his meal.
     26 
     27 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.
     28 
     29 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.
     30 
     31 Please answer him quickly, and you might earn his praise and even enjoy the lunch with him in the elegant Neumanns' way!
     32 
     33 Input
     34 
     35 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.
     36 
     37 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.
     38 
     39 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.
     40 
     41 It is guaranteed that the sum of $k$ over all test cases does not exceed $1000$.
     42 
     43 Output
     44 
     45 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.
     46 
     47 Example
     48 
     49 Input
     50 
     51 ```
     52 5
     53 5 2 3
     54 1 2 3
     55 4 3 3
     56 4 1 2
     57 10 2 6
     58 1 2 3 4 5 7
     59 2 1 1
     60 2
     61 100 76 8
     62 76 75 36 67 41 74 10 77
     63 ```
     64 
     65 Output
     66 
     67 ```
     68 2
     69 0
     70 4
     71 0
     72 2
     73 ```
     74 
     75 Note
     76 
     77 In the first example test case, the nearest floor with an open restaurant would be the floor $4$.
     78 
     79 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.
     80 
     81 In the third example test case, the closest open restaurant is on the $6$-th floor.