From ba5f56120028ea8fed6e4a0e526113c99b827948 Mon Sep 17 00:00:00 2001 From: zinnnn37 Date: Tue, 23 Dec 2025 22:58:09 +0900 Subject: [PATCH] =?UTF-8?q?[20251223]=20BOJ=20/=20G5=20/=20=EB=91=90=20?= =?UTF-8?q?=EA=B0=9C=EC=9D=98=20=ED=83=91=20/=20=EA=B9=80=EB=AF=BC?= =?UTF-8?q?=EC=A7=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... \352\260\234\354\235\230 \355\203\221.md" | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "zinnnn37/202512/23 BOJ G5 \353\221\220 \352\260\234\354\235\230 \355\203\221.md" diff --git "a/zinnnn37/202512/23 BOJ G5 \353\221\220 \352\260\234\354\235\230 \355\203\221.md" "b/zinnnn37/202512/23 BOJ G5 \353\221\220 \352\260\234\354\235\230 \355\203\221.md" new file mode 100644 index 00000000..8f7481ac --- /dev/null +++ "b/zinnnn37/202512/23 BOJ G5 \353\221\220 \352\260\234\354\235\230 \355\203\221.md" @@ -0,0 +1,54 @@ +```java +import java.io.*; + +public class BJ_2118_두_개의_탑 { + + 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 N, ans, half; + private static int[] dist; + + public static void main(String[] args) throws IOException { + init(); + sol(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + ans = 0; + dist = new int[2 * N]; + + for (int i = 0; i < N; i++) { + dist[i] = Integer.parseInt(br.readLine()); + dist[i + N] = dist[i]; + half += dist[i]; + } + half /= 2; + } + + private static void sol() throws IOException { + int left = 0; + int right = 0; + int curDist = 0; + + while (left < N) { + while (true) { + curDist += dist[right++]; + if (curDist > half) { + curDist -= dist[--right]; + break; + } + } + + ans = Math.max(ans, curDist); + curDist -= dist[left++]; + } + bw.write(ans + ""); + bw.flush(); + bw.close(); + br.close(); + } + +} +``` \ No newline at end of file