From 28c27d5be59dc10d67e4c439545e747e7e2ef418 Mon Sep 17 00:00:00 2001 From: Donew <47556347+03do-new30@users.noreply.github.com> Date: Tue, 22 Jul 2025 22:43:26 +0900 Subject: [PATCH] =?UTF-8?q?[20250722]=20BOJ=20/=20G4=20/=20=EC=B9=B4?= =?UTF-8?q?=EB=93=9C=20=EC=A0=95=EB=A0=AC=ED=95=98=EA=B8=B0=20/=20?= =?UTF-8?q?=EC=8B=A0=EB=8F=99=EC=9C=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...25\353\240\254\355\225\230\352\270\260.md" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "03do-new30/202507/22 BOJ G4 \354\271\264\353\223\234 \354\240\225\353\240\254\355\225\230\352\270\260.md" diff --git "a/03do-new30/202507/22 BOJ G4 \354\271\264\353\223\234 \354\240\225\353\240\254\355\225\230\352\270\260.md" "b/03do-new30/202507/22 BOJ G4 \354\271\264\353\223\234 \354\240\225\353\240\254\355\225\230\352\270\260.md" new file mode 100644 index 00000000..05c0a674 --- /dev/null +++ "b/03do-new30/202507/22 BOJ G4 \354\271\264\353\223\234 \354\240\225\353\240\254\355\225\230\352\270\260.md" @@ -0,0 +1,24 @@ +```java +import java.util.*; +import java.io.*; + +public class Main { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); + PriorityQueue pq = new PriorityQueue<>(); + for (int i = 0; i < N; i++) { + pq.offer(Integer.parseInt(br.readLine())); + } + int sum = 0; + while (pq.size() >= 2) { + int a = pq.poll(); + int b = pq.poll(); + pq.offer(a + b); + sum += a + b; + } + System.out.println(sum); + br.close(); + } +} +```