From 8650ac3cb9f03bf2c1eea639f16cde4496d91f3f Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Wed, 16 Jul 2025 23:51:24 +0900 Subject: [PATCH] =?UTF-8?q?[20250716]=20BOJ=20/=20G4=20/=20=ED=9C=B4?= =?UTF-8?q?=EA=B2=8C=EC=86=8C=20=EC=84=B8=EC=9A=B0=EA=B8=B0=20/=20?= =?UTF-8?q?=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \354\204\270\354\232\260\352\270\260.md" | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 "LiiNi-coder/202507/16 BOJ \355\234\264\352\262\214\354\206\214 \354\204\270\354\232\260\352\270\260.md" diff --git "a/LiiNi-coder/202507/16 BOJ \355\234\264\352\262\214\354\206\214 \354\204\270\354\232\260\352\270\260.md" "b/LiiNi-coder/202507/16 BOJ \355\234\264\352\262\214\354\206\214 \354\204\270\354\232\260\352\270\260.md" new file mode 100644 index 00000000..ca4ad3c1 --- /dev/null +++ "b/LiiNi-coder/202507/16 BOJ \355\234\264\352\262\214\354\206\214 \354\204\270\354\232\260\352\270\260.md" @@ -0,0 +1,61 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + +public class B1477 { + private static BufferedReader br; + private static int n; + private static int l; + private static int[] positions; + private static int m; + + 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]); + m = Integer.parseInt(temp[1]); + l = Integer.parseInt(temp[2]); + + positions = new int[n + 2]; + String[] line = br.readLine().split(" "); + for (int i = 0; i < n; i++) { + positions[i + 1] = Integer.parseInt(line[i]); + } + positions[0] = 0; + positions[n + 1] = l; + + Arrays.sort(positions); + + int left = 1; + int right = l; + int answer = 0; + + while (left <= right) { + int mid = (left + right) / 2; + if (canBuild(mid)) { + answer = mid; + right = mid - 1; + } else { + left = mid + 1; + } + } + + System.out.println(answer); + } + + private static boolean canBuild(int maxDist) { + int needed = 0; + for (int i = 1; i < positions.length; i++) { + int dist = positions[i] - positions[i - 1]; + // 해당 구간에서 몇 개의 휴게소가 필요한가? + if (dist > maxDist) { + needed += (dist - 1) / maxDist; + } + } + return needed <= m; + } +} + +```