Advertisement
limimage

Untitled

Sep 12th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define endl "\n"
  4. using namespace std;
  5. using ll = long long;
  6. using ld = long double;
  7. using pii = pair<int, int>;
  8.  
  9. constexpr int N = 1e5+5;
  10.  
  11. int n, ans = 0, s, f, z;
  12. vector<int> vec;
  13.  
  14. void Solve()
  15. {
  16. cin >> n >> z;
  17. for (int i = 0, v; i < n; i++)
  18. cin >> v, vec.push_back(v);
  19. sort(vec.begin(), vec.end());
  20. s = (n-1)/2, f = n-1;
  21. for (; s >= 0 && f > (n-1)/2 ; ans+= (s >= 0 && f > (n-1)/2), f--, s--)
  22. while (s>=0&&(vec[f]-vec[s])<z)
  23. s--;
  24. cout << ans;
  25. }
  26.  
  27. int main()
  28. {
  29. ios::sync_with_stdio(false);
  30. cin.tie(nullptr);
  31. cout.tie(nullptr);
  32. Solve();
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement