import java.util.*;
import java.io.*;
public class tower {
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public float nextFloat() {
return Float.parseFloat(next());
}
public double nextDouble() {
return Float.parseFloat(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
static class CPMath {
static int add(int a, int b) {
a += b;
if (a >= mod) a -= mod;
return a;
}
static int sub(int a, int b) {
a -= b;
if (a < 0) a += mod;
return a;
}
static int multiply(int a, long b) {
b = a * b;
return (int) (b % mod);
}
static int divide(int a, int b) {
return multiply(a, inverse(b));
}
static int inverse(int a) {
return power(a, mod - 2);
}
static int power(int a, int b) {
int r = 1;
while (b > 0) {
if (b % 2 == 1) {
r = multiply(r, a);
}
a = multiply(a, a);
b /= 2;
}
return r;
}
}
static InputReader sc;
static PrintWriter pw;
static int mod = (int) (1e9 + 9);
public static void main(String[] args) throws Exception {
sc = new InputReader(System.in);
pw = new PrintWriter(System.out);
int n = sc.nextInt();
int d = sc.nextInt();
int[] towers = new int[n];
for (int i = 0; i < n; i++) {
towers[i] = sc.nextInt();
}
Arrays.sort(towers);
int left_pointer = n-1;
int result = 1;
for (int i = n-1; i >= 0; i--) {
while (left_pointer - 1 >= 0 && towers[left_pointer - 1] + d >= towers[i]) {
left_pointer--;
}
result = CPMath.multiply(result, i - left_pointer + 1);
}
pw.println(result);
pw.close();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
8668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
8628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
8644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
8812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
8652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
8656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
8536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
8932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
8396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
8684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
8660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
8576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
8656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
8684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
9580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
273 ms |
17364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
385 ms |
19504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
753 ms |
24008 KB |
Output is correct |
2 |
Correct |
747 ms |
23688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
615 ms |
33656 KB |
Output is correct |
2 |
Correct |
596 ms |
35852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
667 ms |
45956 KB |
Output is correct |
2 |
Correct |
734 ms |
50904 KB |
Output is correct |