#include <bits/stdc++.h>
using namespace std;
int n, atleast, dis[200005], ans, lft, rht, middle;
inline bool check(int x) {
  for (register int i = 1; i <= x; i++) {
    if (dis[n - x + i] - dis[i] < atleast) {
      return false;
    }
  }
  return true;
}
int main() {
  scanf("%d%d", &n, &atleast);
  rht = n / 2;
  for (register int i = 1; i <= n; i++) {
    scanf("%d", &dis[i]);
    dis[i] -= atleast;
  }
  sort(dis + 1, dis + n + 1);
  while (lft <= rht) {
    middle = (lft + rht) >> 1;
    switch (check(middle)) {
      case true:
        lft = middle + 1;
        break;
      case false:
        rht = middle - 1;
        break;
    }
  }
  printf("%d\n", rht);
  return 0;
}
