-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBalancedRound.java
More file actions
29 lines (28 loc) · 854 Bytes
/
Copy pathBalancedRound.java
File metadata and controls
29 lines (28 loc) · 854 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 BalancedRound {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
for (int i = 0; i < t; i++) {
int n = scanner.nextInt();
int k = scanner.nextInt();
int count = 1 ;
int max =1;
int[] a = new int[n];
for (int j = 0; j < n; j++) {
a[j] = scanner.nextInt();
}
Arrays.sort(a);
for (int j = 1; j < n; j++) {
if(a[j]-a[j-1] <= k) count++;
else {
max = Math.max(max,count);
count=1;
}
}
max = Math.max(max,count);
System.out.println(n-max);
}
}
}