fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4.  
  5.  
  6.  
  7. int main() {
  8. ios::sync_with_stdio(false);
  9. cin.tie(nullptr);
  10. int t;
  11. cin >> t;
  12. while (t--) {
  13. int n;
  14. ll k;
  15. cin >> n >> k;
  16.  
  17. vector<ll> b(n);
  18. for (int i = 0; i < n; i++) {
  19. cin >> b[i];
  20. }
  21.  
  22. // Sort bar‐positions
  23. sort(b.begin(), b.end());
  24. int L = (n - k + 1) / 2;
  25. int R = (n + k + 2) / 2;
  26. cout << b[R] - b[L] + 1 << '\n';
  27.  
  28.  
  29.  
  30. }
  31. return 0;
  32. }
  33.  
  34.  
Success #stdin #stdout 0s 5320KB
stdin
4
4 0
1 2 3 4
5 2
7 6 6 7 1
3 1
6 7 9
6 2
5 1 9 10 13 2
stdout
2
2
98539
9