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); + } +} + +```