fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. ios::sync_with_stdio(false);
  7. cin.tie(0);
  8. int tt;
  9. cin >> tt;
  10. while (tt--) {
  11. int n, m, a, b;
  12. cin >> n >> m >> a >> b;
  13. vector<int> s(m);
  14. for (int i = 0; i < m; i++) {
  15. cin >> s[i];
  16. }
  17. sort(s.begin(), s.end());
  18. int cnt = abs(a - b) - 1;
  19. int total = (a < b ? b - 1 : n - b) - 1;
  20. // cout << total << " " << cnt << " ";
  21. int u = total - cnt;
  22. // cout <<u << endl;
  23. int ans = 0;
  24. for (int i = 0; i < m; i++) {
  25. u = max(u + 1, s[i]);
  26. if (u > total) {
  27. break;
  28. }
  29. ans += 1;
  30. }
  31. cout << ans << '\n';
  32. }
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5388KB
stdin
3
7 2 3 6
1 4
7 2 3 6
5 1
7 2 3 6
4 4
stdout
2
1
1