# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
735260 | 2023-05-03T18:58:26 Z | dxf | A Huge Tower (CEOI10_tower) | Java 11 | 0 ms | 0 KB |
// Source: https://usaco.guide/general/io import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(r.readLine()); int n = Integer.parseInt(st.nextToken()); int d = Integer.parseInt(st.nextToken()); int[] sizes = new int[n]; st = new StringTokenizer(r.readLine()); for (int i = 0; i < n; i++) { sizes[i] = Integer.parseInt(st.nextToken()); } long[] former = new long[n]; former[0] = 1; Arrays.sort(sizes); for (int i = 1; i < n; i++) { long count = 1; int loc = i-1;; while (loc >= 0 && sizes[loc]+d >= sizes[i]) { count ++; loc--; } former[i] = ((long) former[i-1]) * count; } System.out.println(former[n-1]); } }