AcWing 4483. 格斗场
:::info
i在前,j在后的例题
:::
思路:
排序 + 双指针
static int N = 200010;
static int[] a = new int[N];
static int n;
static void solve() {
n = ni();
int k = ni();
for (int i = 0; i < n; i++)
a[i] = ni();
Arrays.sort(a, 0, n);
int cnt = n;
for (int i = 0, j = 0; i < n; i++) {
while (j < n && a[j] - a[i] <= k)
j++;
if (a[j - 1] > a[i])
cnt--;
}
out.println(cnt);
}