# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
934200 | 2024-02-27T01:07:58 Z | tkaim | A Huge Tower (CEOI10_tower) | Java 11 | 0 ms | 0 KB |
import java.io.*; import java.util.Arrays; import java.util.Comparator; import java.util.StringTokenizer; public class App { public static void main(String[] args) throws IOException { //BufferedReader reader = new BufferedReader(new FileReader(new File("diamond.in"))); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); //PrintWriter out = new PrintWriter(new FileWriter(new File("diamond.out"))); StringTokenizer sTokenizer = new StringTokenizer(reader.readLine()); int numCount = Integer.parseInt(sTokenizer.nextToken()); int difference = Integer.parseInt(sTokenizer.nextToken()); int[] blocks = new int[numCount]; sTokenizer = new StringTokenizer(reader.readLine()); for(int i = 0; i < numCount; i++) { blocks[i] = Integer.parseInt(sTokenizer.nextToken()); } Arrays.sort(blocks); int answer = 1; int upBlock = 1; for(int i = 0; i < numCount; i++) { if(upBlock >= numCount - 1) { int num = numCount - 1 - i; if(num != 0) { answer *= num; } continue; } if(blocks[upBlock] > difference + blocks[i]) { int num = upBlock - i; if(num != 0) { answer *= num; } continue; } i--; upBlock++; } out.println(answer); out.close(); } }