From 3d14091fe5e4aca7e698024360d69c1919dde1a9 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Tue, 5 Aug 2025 21:29:12 +0900 Subject: [PATCH] =?UTF-8?q?[20250805]=20BOJ=20/=20G5=20/=20=EC=88=98=20?= =?UTF-8?q?=EA=B3=A0=EB=A5=B4=EA=B8=B0=20/=20=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \352\263\240\353\245\264\352\270\260.md" | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 "lkhyun/202508/05 BOJ G5 \354\210\230 \352\263\240\353\245\264\352\270\260.md" diff --git "a/lkhyun/202508/05 BOJ G5 \354\210\230 \352\263\240\353\245\264\352\270\260.md" "b/lkhyun/202508/05 BOJ G5 \354\210\230 \352\263\240\353\245\264\352\270\260.md" new file mode 100644 index 00000000..10549fe4 --- /dev/null +++ "b/lkhyun/202508/05 BOJ G5 \354\210\230 \352\263\240\353\245\264\352\270\260.md" @@ -0,0 +1,41 @@ +```java +import java.util.*; +import java.io.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N,M; + static int[] A; + + public static void main(String[] args) throws Exception { + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + A = new int[N]; + + for (int i = 0; i < N; i++) { + A[i] = Integer.parseInt(br.readLine()); + } + Arrays.sort(A); + + int ans = Integer.MAX_VALUE; + int left = 0, right = 0; + + while (right < N && left < N) { + int d = A[right] - A[left]; + + if (d >= M) { + ans = Math.min(ans, d); + left++; + } else { + right++; + } + } + bw.write(ans+""); + bw.close(); + } +} +```