#include <bits/stdc++.h>
using namespace std;
mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const long long maxn = (long long)1e6 + 6;
const long double EPS = 1e-9;
const long long INF = (long long)1e18 + 18;
const long long mod = (long long)1e9 + 7;
long long n, z, a[maxn];
bool works(long long k) {
  if (2 * k > n) return false;
  vector<long long> big;
  for (long long i = n - 1; (long long)big.size() < k && i >= 0; i--) {
    big.push_back(a[i]);
  }
  reverse(big.begin(), big.end());
  for (long long i = 0; i < k; i++) {
    if (big[i] - a[i] < z) return false;
  }
  return true;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> z;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  long long low = 0, high = n / 2;
  while (low < high) {
    long long mid = (low + high + 1) >> 1;
    if (works(mid)) {
      low = mid;
    } else {
      high = mid - 1;
    }
  }
  cout << low << '\n';
  return 0;
}
