# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
735260 | dxf | A Huge Tower (CEOI10_tower) | Java | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Source: https://usaco.guide/general/io
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(r.readLine());
int n = Integer.parseInt(st.nextToken());
int d = Integer.parseInt(st.nextToken());
int[] sizes = new int[n];
st = new StringTokenizer(r.readLine());
for (int i = 0; i < n; i++) {
sizes[i] = Integer.parseInt(st.nextToken());
}
long[] former = new long[n];
former[0] = 1;
Arrays.sort(sizes);
for (int i = 1; i < n; i++) {
long count = 1;
int loc = i-1;;
while (loc >= 0 && sizes[loc]+d >= sizes[i]) {
count ++;
loc--;
}
former[i] = ((long) former[i-1]) * count;
}
System.out.println(former[n-1]);
}
}