➤ Problem Link : 1293A. ConneR and the A.R.C. Markland
✅ C++ Solution :
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
int t;
cin>>t;
while(t--)
{
ll n,s,k,a;
cin>>n>>s>>k;
unordered_set<ll> us;
for(int i=1;i<=k;i++)
{
cin>>a;
us.insert(a);
}
ll ans=0;
for(ll i=0;i<=1001;i++)
{
if((s+i<=n && us.find(s+i)==us.end()) || (s-i > 0 && us.find(s-i)==us.end()))
{
ans=i;
break;
}
}
cout<<ans<<"\n";
}
}
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!
