# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
685817 | bruhgamer | 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.
//package USACO;
import java.util.*;
import java.io.*;
public class hugetower {
public static void main(String[]args) throws IOException{
Kattio io = new Kattio();
int n = io.nextInt();
int d = io.nextInt();
int[]arr = new int[n];
int[]valuesless = new int[n];
for(int i = 0; i < n; i++) {
arr[i] = io.nextInt();
}
Arrays.sort(arr);
for(int i = 0; i < n; i++) {
for(int j = i-1; j >= 0; j--) {
if(arr[i] - arr[j] <= d) {
valuesless[i]++;
}
else {
break;
}
}
}
long[]values = new long[n];
values[0] = 1;
for(int i = 1; i < n ; i++) {
values[i] = (values[i-1] * (valuesless[i] + 1)) % 1000000007L;
}
io.println(values[n-1]);
io.close();
}
static class Kattio extends PrintWriter {
private BufferedReader r;
private StringTokenizer st;
// standard input
public Kattio() { this(System.in, System.out); }
public Kattio(InputStream i, OutputStream o) {
super(o);
r = new BufferedReader(new InputStreamReader(i));
}
// USACO-style file input
public Kattio(String problemName) throws IOException {
super(problemName + ".out");
r = new BufferedReader(new FileReader(problemName + ".in"));
}
// returns null if no more input
public String next() {
try {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(r.readLine());
return st.nextToken();
} catch (Exception e) { }
return null;
}
public int nextInt() { return Integer.parseInt(next()); }
public double nextDouble() { return Double.parseDouble(next()); }
public long nextLong() { return Long.parseLong(next()); }
}
}