From 4e47aed548c4984491e3805168dfb135bfb371fa Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Wed, 2 Jul 2025 23:53:05 +0900 Subject: [PATCH] =?UTF-8?q?[20250702]=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=84=A4=EC=A7=84=EC=98=81?= 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" | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 "Seol-JY/202507/02 BOJ G4 \354\271\264\353\223\234 \354\240\225\353\240\254\355\225\230\352\270\260.md" diff --git "a/Seol-JY/202507/02 BOJ G4 \354\271\264\353\223\234 \354\240\225\353\240\254\355\225\230\352\270\260.md" "b/Seol-JY/202507/02 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..999696f2 --- /dev/null +++ "b/Seol-JY/202507/02 BOJ G4 \354\271\264\353\223\234 \354\240\225\353\240\254\355\225\230\352\270\260.md" @@ -0,0 +1,30 @@ +```java +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.IOException; +import java.util.PriorityQueue; + +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.add(Long.parseLong(br.readLine())); + } + + long total = 0; + while (pq.size() > 1) { + long a = pq.poll(); + long b = pq.poll(); + long sum = a + b; + total += sum; + pq.add(sum); + } + + System.out.println(total); + } +} + +```