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. vector<ll> b(n);
  17. for (int i = 0; i < n; i++) {
  18. cin >> b[i];
  19. }
  20. // Sort bar‐positions
  21. sort(b.begin(), b.end());
  22. ll L = (n - k + 1) / 2;
  23. ll R = (n + k + 2) / 2;
  24. cout << b[R] - b[L] + 1 << '\n';
  25.  
  26. }
  27. return 0;
  28. }
  29.  
  30.  
Success #stdin #stdout 0.01s 5308KB
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