
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
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<Integer> pq = new PriorityQueue<>();
for (int i = 0; i < N; i++) {
pq.add(Integer.parseInt(br.readLine()));
}
int cards1, cards2;
int result = 0;
while (pq.size() != 1) {
cards1 = pq.remove();
cards2 = pq.remove();
result += cards1 + cards2;
pq.add(cards1 + cards2);
}
System.out.println(result);
}
}
'Coding Test > 백준' 카테고리의 다른 글
[백준/자바] 1931 - 회의실 배정 (0) | 2023.08.08 |
---|---|
[백준/자바] 1744 - 수 묶기 (0) | 2023.08.08 |
[백준/자바] 11047 - 동전 0 (0) | 2023.08.08 |
[백준/자바] 1300 - K번째 수 (0) | 2023.08.07 |
[백준/자바] 2343 - 기타 레슨 (0) | 2023.08.07 |