# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
365121 | dg2004 | 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.util.*;
import java.io.*;
public class Solution {
static int MOD = 1000000009;
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer token = new StringTokenizer(in.readLine());
int n = Integer.parseInt(token.nextToken()), d = Integer.parseInt(token.nextToken());
int[] ar = new int[n];
token = new StringTokenizer(in.readLine());
for (int a = 0; a < n; a++)
ar[a] = Integer.parseInt(token.nextToken());
Arrays.sort(ar);
int r = 0;
int ans = 1;
for (int l = 0; l < n; l++) {
while (r < n - 1 && ar[r + 1] - ar[l] <= d)
r++;
int dist = r - l + 1;
ans = (int)(((long)ans * dist) % MOD);
}
System.out.println(ans);
}
}