From 8ba856510730632c0ce945424824a34f3d19cf62 Mon Sep 17 00:00:00 2001 From: zinnnn37 Date: Fri, 12 Sep 2025 22:27:30 +0900 Subject: [PATCH] =?UTF-8?q?[20250912]=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?=EA=B9=80=EB=AF=BC=EC=A7=84?= 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" | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 "zinnnn37/202509/12 BOJ G4 \354\271\264\353\223\234 \354\240\225\353\240\254\355\225\230\352\270\260.md" diff --git "a/zinnnn37/202509/12 BOJ G4 \354\271\264\353\223\234 \354\240\225\353\240\254\355\225\230\352\270\260.md" "b/zinnnn37/202509/12 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..06c01204 --- /dev/null +++ "b/zinnnn37/202509/12 BOJ G4 \354\271\264\353\223\234 \354\240\225\353\240\254\355\225\230\352\270\260.md" @@ -0,0 +1,47 @@ +```java +import java.io.*; +import java.util.PriorityQueue; +import java.util.Queue; + +public class BJ_1715_카드_정렬하기 { + + 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; + private static int ans; + + private static Queue pq; + + public static void main(String[] args) throws IOException { + init(); + sol(); + } + + private static void init() throws IOException { + pq = new PriorityQueue<>(); + ans = 0; + + N = Integer.parseInt(br.readLine()); + while (N-- > 0) { + int n = Integer.parseInt(br.readLine()); + pq.offer(n); + } + } + + private static void sol() throws IOException { + while (pq.size() > 1) { + int a = pq.poll(); + int b = pq.poll(); + + pq.add(a + b); + ans += a + b; + } + bw.write(ans + ""); + bw.flush(); + bw.close(); + br.close(); + } + +} +``` \ No newline at end of file