Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- #include <vector>
- using namespace std;
- int main()
- {
- int t; cin >> t;
- while (t--)
- {
- int broj = INT_MAX;
- int n, s, k; cin >> n >> s >> k;
- vector <int> a(k + 1);
- vector <bool> akop(n + 1);
- for (int i = 1; i <= k; i++)
- {
- cin >> a[i];
- akop[a[i]] = true;
- }
- int i = s, j = s;
- while (1)
- {
- if (!akop[i])
- {
- broj = abs(s - i);
- break;
- }
- if (!akop[j])
- {
- broj = abs(s - j);
- break;
- }
- if (j > 1)j--;
- if (i <= n)i++;
- }
- cout << endl << broj << endl << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement