File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.PriorityQueue ;
4+ import java.util.Queue ;
5+
6+ public class BJ_1715_ 카드_정렬하기 {
7+
8+ private static final BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
9+ private static final BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System . out));
10+
11+ private static int N ;
12+ private static int ans;
13+
14+ private static Queue<Integer > pq;
15+
16+ public static void main (String [] args ) throws IOException {
17+ init();
18+ sol();
19+ }
20+
21+ private static void init () throws IOException {
22+ pq = new PriorityQueue<> ();
23+ ans = 0 ;
24+
25+ N = Integer . parseInt(br. readLine());
26+ while (N -- > 0 ) {
27+ int n = Integer . parseInt(br. readLine());
28+ pq. offer(n);
29+ }
30+ }
31+
32+ private static void sol () throws IOException {
33+ while (pq. size() > 1 ) {
34+ int a = pq. poll();
35+ int b = pq. poll();
36+
37+ pq. add(a + b);
38+ ans += a + b;
39+ }
40+ bw. write(ans + " " );
41+ bw. flush();
42+ bw. close();
43+ br. close();
44+ }
45+
46+ }
47+ ```
You can’t perform that action at this time.
0 commit comments