#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int n, z;
int a[maxn];
bool judge(int x) {
  int nowi = n, nowj = x;
  while (x--) {
    if (a[nowi] - a[nowj] < z) return false;
    nowi--;
    nowj--;
  }
  return true;
}
int main() {
  cin >> n >> z;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  int ans = 0;
  int l = 0, r = n / 2;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (judge(mid)) {
      ans = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  cout << ans << endl;
  return 0;
}
