#include<bits/stdc++.h> #define SINGLE_INPUT #define ll long long #define N 500005 #define MOD 998244353 usingnamespace std;
voidsol(){ ll n, z; cin >> n >> z; vector<ll> a(n); for (ll& i : a) cin >> i; sort(a.begin(), a.end()); auto check = [&](int x) { for (int i = 0; i < x; i++) { if (a[n - x + i] - a[i] < z) returnfalse; } returntrue; }; int l = 1, r = n / 2 + 1; while (l < r) { // cout << l << " " << r << endl; int m = l + r >> 1; if (check(m)) { l = m + 1; } else { r = m; } } cout << r - 1 << "\n"; }