# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
934813 | jeli26 | 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.
import java.io.*;
import java.util.*;
public class Main {
static int MAX = 1000000009;
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(in.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
int[] blocks = new int[n];
st = new StringTokenizer(in.readLine());
for(int i = 0; i < n; i++) {
blocks[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(blocks);
int ans = 1;
int r = 1;
for(int l = 0; l < n; l++) {
while(r < n && blocks[r] - blocks[l] <= m) {
r++;
}
int mult = Math.max((r - l) % MAX, 1);
ans = ((ans * r % MAX) - (ans * l % MAX)) % MAX;
}
System.out.println(ans);
}
}