We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3d09166 commit cd340e9Copy full SHA for cd340e9
week1/BOJ_2785(체인).java
@@ -0,0 +1,29 @@
1
+import java.io.*;
2
+import java.util.*;
3
+
4
+public class Main {
5
6
+ public static void main(String[] args) throws IOException {
7
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8
+ int N = Integer.parseInt(br.readLine());
9
+ StringTokenizer st = new StringTokenizer(br.readLine());
10
+ PriorityQueue<Integer> q = new PriorityQueue<>();
11
+ for(int i=0; i<N; i++) {
12
+ q.offer(Integer.parseInt(st.nextToken()));
13
+ }
14
15
+ int count = 0;
16
+ int link = q.size() - 1;
17
+ while(true) {
18
+ int chain = q.peek();
19
+ if(link > chain) {
20
+ link -= chain + 1;
21
+ count += q.poll();
22
+ }else {
23
+ count += link;
24
+ break;
25
26
27
+ System.out.println(count);
28
29
+}
0 commit comments