From c0cbb4981e75748dd0e3c09b7577e0a5524451c9 Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Sat, 8 Nov 2025 23:53:12 +0900 Subject: [PATCH] =?UTF-8?q?[20251108]=20BOJ=20/=20G5=20/=20=EA=B8=B0?= =?UTF-8?q?=ED=83=80=20=EB=A0=88=EC=8A=A8=20/=20=EC=84=A4=EC=A7=84?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \353\240\210\354\212\250.md\342\200\216" | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 "Seol-JY/202511/08 BOJ G5 \352\270\260\355\203\200 \353\240\210\354\212\250.md\342\200\216" diff --git "a/Seol-JY/202511/08 BOJ G5 \352\270\260\355\203\200 \353\240\210\354\212\250.md\342\200\216" "b/Seol-JY/202511/08 BOJ G5 \352\270\260\355\203\200 \353\240\210\354\212\250.md\342\200\216" new file mode 100644 index 00000000..2b7b5397 --- /dev/null +++ "b/Seol-JY/202511/08 BOJ G5 \352\270\260\355\203\200 \353\240\210\354\212\250.md\342\200\216" @@ -0,0 +1,61 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int N = Integer.parseInt(st.nextToken()); + int M = Integer.parseInt(st.nextToken()); + + int[] lectures = new int[N]; + st = new StringTokenizer(br.readLine()); + + int left = 0; + int right = 0; + + for (int i = 0; i < N; i++) { + lectures[i] = Integer.parseInt(st.nextToken()); + left = Math.max(left, lectures[i]); + right += lectures[i]; + } + + int answer = right; + + while (left <= right) { + int mid = (left + right) / 2; + + if (canDivide(lectures, M, mid)) { + answer = mid; + right = mid - 1; + } else { + left = mid + 1; + } + } + + System.out.println(answer); + } + + private static boolean canDivide(int[] lectures, int M, int size) { + int count = 1; + int currentSum = 0; + + for (int lecture : lectures) { + if (currentSum + lecture > size) { + count++; + currentSum = lecture; + + if (count > M) { + return false; + } + } else { + currentSum += lecture; + } + } + + return true; + } +} +```