diff --git "a/LiiNi-coder/202507/18 BOJ \352\265\254\352\260\204 \353\202\230\353\210\204\352\270\260 2.md" "b/LiiNi-coder/202507/18 BOJ \352\265\254\352\260\204 \353\202\230\353\210\204\352\270\260 2.md" new file mode 100644 index 00000000..c3b0d1cd --- /dev/null +++ "b/LiiNi-coder/202507/18 BOJ \352\265\254\352\260\204 \353\202\230\353\210\204\352\270\260 2.md" @@ -0,0 +1,59 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main { + private static BufferedReader br; + private static int n; + private static int k; + private static int[] arr; + + public static void main(String[] args) throws IOException { + br = new BufferedReader(new InputStreamReader(System.in)); + var temp = br.readLine().split(" "); + n = Integer.parseInt(temp[0]); + k = Integer.parseInt(temp[1]); + + arr = new int[n]; + var st = new StringTokenizer(br.readLine()); + for (int i = 0; i < n; i++) { + arr[i] = Integer.parseInt(st.nextToken()); + } + + int left = 0; + int right = 10000; + int answer = 10000; + + while (left <= right) { + int mid = (left + right) / 2; + if (canDivide(mid)) { + answer = mid; + right = mid - 1; + } else { + left = mid + 1; + } + } + + System.out.println(answer); + } + + private static boolean canDivide(int maxGap) { + int count = 1; + int min = arr[0]; + int max = arr[0]; + + for (int i = 1; i < n; i++) { + min = Math.min(min, arr[i]); + max = Math.max(max, arr[i]); + if (max - min > maxGap) { + count++; + min = arr[i]; + max = arr[i]; + } + } + return count <= k; + } +} +```