We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent cae4918 commit 90c8a44Copy full SHA for 90c8a44
1 file changed
정건우/10주차/260306.java
@@ -0,0 +1,37 @@
1
+//https://www.acmicpc.net/problem/1715
2
+import java.io.BufferedReader;
3
+import java.io.IOException;
4
+import java.io.InputStreamReader;
5
+import java.util.PriorityQueue;
6
+
7
+public class BOJ_G4_1715_카드정렬하기 {
8
+ public static void main(String[] args) throws IOException {
9
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10
11
+ int N = Integer.parseInt(br.readLine());
12
13
+ if(N == 1) {
14
+ System.out.println(0);
15
+ return;
16
+ }
17
18
+ PriorityQueue<Integer> pq = new PriorityQueue<>();
19
20
+ for (int i = 0; i < N; i++) {
21
+ pq.add(Integer.parseInt(br.readLine()));
22
23
24
+ int ans = 0;
25
26
+ while (pq.size() >= 2) {
27
+ int a = pq.poll();
28
+ int b = pq.poll();
29
30
+ pq.add(a+b);
31
+ ans += a+b;
32
33
34
+ System.out.println(ans);
35
36
37
+}
0 commit comments