import java.util.PriorityQueue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
int n = kb.nextInt();
int answer = 0;
PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
for(int i=0; i<n; i++) {
pq.add(kb.nextInt());
}
while(pq.size()>1) {
int a = pq.remove();
int b = pq.remove();
answer += a+ b;
pq.add(a+b);
}
System.out.println(answer);
}
}
'공부기록 > 백준' 카테고리의 다른 글
[백준] 10986번 나머지 합 (0) | 2023.12.11 |
---|---|
[백준] 11866번 요세푸스 문제 0 (0) | 2023.12.05 |
[백준] 10810번 공 넣기 (0) | 2023.11.21 |
[백준] 11660번 구간 합 구하기 5 (1) | 2023.11.21 |
[백준] 11508번 2+1 세일 (2) | 2023.11.21 |