Skip to content

Commit cd340e9

Browse files
committed
BOJ_2785 : 체인
1 parent 3d09166 commit cd340e9

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

week1/BOJ_2785(체인).java

+29
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)