-
Notifications
You must be signed in to change notification settings - Fork 0
/
A.cpp
37 lines (35 loc) · 814 Bytes
/
A.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main(){
fast;
ll t;
cin>>t;
while(t--){
ll n,s,k,temp;
cin>>n>>s>>k;
unordered_set<ll> mp;
for(ll i=0;i<k;i++){
cin>>temp;
mp.insert(temp);
}
ll i=s,ans1=-1e10,ans2=1e10;
while(i>0){
if(mp.find(i)==mp.end()){
ans1= i;
break;
} i--;
}
i = s;
while(i<=n){
if(mp.find(i)==mp.end()){
ans2 = i;
break;
} i++;
}
//cout<<i<<" "<<ans1<<" "<<ans2<<endl;
cout<<min(s-ans1,ans2-s)<<endl;
}
return 0;
}