#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
long long valid(vector<long long> &A, long long k, long long z) {
  int n = A.size();
  for (int i = 0; i < n; ++i) {
    if (n - k + i < n)
      if (A[n - k + i] - A[i] < z) {
        return false;
      }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, z;
  cin >> n >> z;
  vector<long long> A(n);
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  int ans = 0;
  long long lo = 0, hi = n / 2, mid;
  while (lo <= hi) {
    mid = lo + (hi - lo) / 2;
    if (valid(A, mid, z)) {
      ans = mid;
      lo = mid + 1;
    } else {
      hi = mid - 1;
    }
  }
  cout << ans << "\n";
  return 0;
}
