Saleh127

CF 1293A

Jul 27th, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. #define fellow_junior ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  6. int main()
  7. {
  8. fellow_junior
  9. test
  10. {
  11. ll n,s,k,c,d,e,i,j,l;
  12. map<ll,ll>a;
  13. cin>>n>>s>>k;
  14. a.clear();
  15. for(i=0;i<k;i++)
  16. {
  17. cin>>c;
  18. a[c]=1;
  19. }
  20. for(i=0;i<n;i++)
  21. {
  22. if(s+i<=n && a.find(s+i)==a.end())
  23. {
  24. cout<<i<<endl;
  25. break;
  26. }
  27. else if(s-i>=1 && a.find(s-i)==a.end())
  28. {
  29. cout<<i<<endl;
  30. break;
  31. }
  32. }
  33. }
  34.  
  35.  
  36. return 0;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment