#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
const long long INF = 1e18;
const long long M = 1e9 + 7;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, z;
  cin >> n >> z;
  const long long maxn = 1e6;
  static long long a[maxn];
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a, a + n);
  long long l = 0, r = n / 2, res = 0;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    bool ok = 1;
    for (long long i = 0; i < mid; ++i) {
      if (a[n - mid + i] - a[i] < z) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      l = mid + 1;
      res = mid;
    } else {
      r = mid - 1;
    }
  }
  cout << res << endl;
  return 0;
}
