#include <bits/stdc++.h>
using namespace std;
const double pi = 3.141592653589793238463;
int n, z;
int a[200009];
bool check(int k) {
  int i = 0, j = n - k;
  if (k > n / 2) return 0;
  while (k--) {
    if (a[j] - a[i] < z) return 0;
    i++;
    j++;
  }
  return 1;
}
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  cin >> n >> z;
  for (int i = 0; i < (n); i++) cin >> a[i];
  sort(a, a + n);
  int s = 0, e = n, ans = 0;
  while (s <= e) {
    int k = (s + e) / 2;
    if (check(k))
      ans = k, s = k + 1;
    else
      e = k - 1;
  }
  cout << ans << '\n';
  return 0;
}
