# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
685817 | 2023-01-25T01:43:37 Z | bruhgamer | A Huge Tower (CEOI10_tower) | Java 11 | 0 ms | 0 KB |
//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()); } } }