-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeforces.java
More file actions
29 lines (28 loc) · 844 Bytes
/
Copy pathCodeforces.java
File metadata and controls
29 lines (28 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.Arrays;
import java.util.Scanner;
public class Codeforces {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
while (t-- > 0) {
int n = scanner.nextInt();
int k = scanner.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = scanner.nextInt();
}
Arrays.sort(a);
int count = 1;
int max = 1;
for (int i = 1; i < n; i++) {
if (a[i]-a[i-1] <= k) count++;
else {
max = Math.max(max, count);
count = 1;
}
}
max = Math.max(max, count);
System.out.println(n-max);
}
}
}