From e861f25c2acd57dfd9c939b4b0738ca2ae295e69 Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Thu, 17 Jul 2025 23:44:07 +0900 Subject: [PATCH] =?UTF-8?q?[20250717]=20BOJ=20/=20G4=20/=20=EA=B3=B5?= =?UTF-8?q?=EC=9C=A0=EA=B8=B0=20=EC=84=A4=EC=B9=98=20/=20=EC=9D=B4?= =?UTF-8?q?=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\352\270\260 \354\204\244\354\271\230.md" | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 "LiiNi-coder/202507/17 BOJ \352\263\265\354\234\240\352\270\260 \354\204\244\354\271\230.md" diff --git "a/LiiNi-coder/202507/17 BOJ \352\263\265\354\234\240\352\270\260 \354\204\244\354\271\230.md" "b/LiiNi-coder/202507/17 BOJ \352\263\265\354\234\240\352\270\260 \354\204\244\354\271\230.md" new file mode 100644 index 00000000..9013ed48 --- /dev/null +++ "b/LiiNi-coder/202507/17 BOJ \352\263\265\354\234\240\352\270\260 \354\204\244\354\271\230.md" @@ -0,0 +1,55 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + +public class B2110 { + private static BufferedReader br; + private static int n; + private static int c; + private static int[] houses; + + public static void main(String[] args) throws IOException { + br = new BufferedReader(new InputStreamReader(System.in)); + String[] temp = br.readLine().split(" "); + n = Integer.parseInt(temp[0]); + c = Integer.parseInt(temp[1]); + + houses = new int[n]; + for (int i = 0; i < n; i++) { + houses[i] = Integer.parseInt(br.readLine()); + } + + Arrays.sort(houses); + + int left = 1; + int right = houses[n - 1] - houses[0]; + int answer = 0; + + while (left <= right) { + int mid = (left + right) / 2; + if (canInstall(mid)) { + answer = mid; + left = mid + 1; + } else { + right = mid - 1; + } + } + + System.out.println(answer); + } + + private static boolean canInstall(int minDist) { + int count = 1; + int lastInstalled = houses[0]; + for (int i = 1; i < n; i++) { + if (houses[i] - lastInstalled >= minDist) { + count++; + lastInstalled = houses[i]; + } + } + return count >= c; + } +} +```