From accb335a78ea5c0c176e8ab9cbdb9b53f454bd90 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Sun, 23 Nov 2025 17:17:50 +0900 Subject: [PATCH] =?UTF-8?q?[20251123]=20BOJ=20/=20G5=20/=20=EA=B8=B0?= =?UTF-8?q?=ED=83=80=20=EB=A0=88=EC=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\355\203\200 \353\240\210\354\212\250.md" | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 "Ukj0ng/202511/23 BOJ G5 \352\270\260\355\203\200 \353\240\210\354\212\250.md" diff --git "a/Ukj0ng/202511/23 BOJ G5 \352\270\260\355\203\200 \353\240\210\354\212\250.md" "b/Ukj0ng/202511/23 BOJ G5 \352\270\260\355\203\200 \353\240\210\354\212\250.md" new file mode 100644 index 00000000..02147576 --- /dev/null +++ "b/Ukj0ng/202511/23 BOJ G5 \352\270\260\355\203\200 \353\240\210\354\212\250.md" @@ -0,0 +1,74 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static int[] lectures; + private static int N, M, min; + + public static void main(String[] args) throws IOException { + init(); + int answer = binarySearch(); + + bw.write(answer + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + min = 10000; + + lectures = new int[N]; + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + lectures[i] = Integer.parseInt(st.nextToken()); + min = Math.min(min, lectures[i]); + } + } + + private static int binarySearch() { + int left = min; + int right = 1000000000; + int result = 0; + + while (left <= right) { + int mid = left + (right - left) / 2; + + if (valid(mid)) { + result = mid; + right = mid - 1; + } else { + left = mid + 1; + } + } + + return result; + } + + private static boolean valid(int target) { + int time = 0; + int count = 1; + + for (int lecture : lectures) { + if (lecture > target) { + return false; + } + if (time + lecture <= target) { + time += lecture; + } else { + count++; + time = lecture; + } + } + + return count <= M; + } +} +```