Lang:Java
Edit12345678910111213141516171819202122232425262728293031import java.util.*;public class Main {public static void main(String[] args){Scanner sc = new Scanner(System.in);int a[] = new int[100001];int t = sc.nextInt();while(t-- != 0) {int n = sc.nextInt();int k = sc.nextInt();Arrays.fill(a, 0);for (int i = 0; i < n; i++) {a[sc.nextInt()]++;}Boolean yes = true;for(int i = 1; i < 100001 && yes && n > 0; i++) {if (a[i] != 0) {int m = a[i];for (int j = i; j < i + k; j++){//System.out.println("i j:" + i + " " + j + " " + a[i] + " " + a[j]);if (m > a[j]) {yes = false;break;}a[j] -= m;n -= m;}}}