728x90
https://www.acmicpc.net/problem/12845
package BAEKJOON.Silver.Ⅲ;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
public class NO12845 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
int n = sc.nextInt();
int gold = 0;
for (int i = 0; i < n; i++) {
pq.add(sc.nextInt());
}
while (pq.size() != 1) {
int num = pq.poll(); // 40
gold += num + pq.poll(); // 40 + 30 = 70
pq.add(num);
}
System.out.println(gold);
}
}
728x90
'Algorithm & SQL > BAEKJOON' 카테고리의 다른 글
백준 JAVA 11728 배열 합치기 (0) | 2022.08.16 |
---|---|
백준 JAVA 2018 수들의 합5 (0) | 2022.08.15 |
백준 JAVA 4796 캠핑 (0) | 2022.08.14 |
백준 JAVA 13458 시험 감독 (0) | 2022.08.14 |
백준 JAVA 2217 로프 (0) | 2022.08.13 |
댓글