Skip to content

Commit 6d97c7e

Browse files
authored
Merge pull request #1376 from AlgorithmWithGod/0224LJH
[20251111] BOJ / G5 / 모독 / 이종환
2 parents 36d4a9f + 5b11734 commit 6d97c7e

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

0224LJH/202511/11 BOJ 모독.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
```java
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
import java.io.*;
6+
import java.util.*;
7+
8+
public class Main {
9+
10+
static int cnt;
11+
static PriorityQueue<Integer> pq = new PriorityQueue<>();
12+
13+
public static void main (String[] args) throws NumberFormatException, IOException {
14+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
15+
cnt = Integer.parseInt(br.readLine());
16+
for (int i = 0; i < cnt; i++) {
17+
pq.add(Integer.parseInt(br.readLine()));
18+
}
19+
20+
int goal = 1;
21+
long hackerCnt = 0;
22+
23+
while(!pq.isEmpty()) {
24+
if (goal == pq.peek()) {
25+
goal++;
26+
pq.poll();
27+
} else if (goal > pq.peek()) {
28+
pq.poll();
29+
} else {
30+
hackerCnt += pq.peek()-goal;
31+
pq.poll();
32+
goal++;
33+
}
34+
}
35+
36+
System.out.println(hackerCnt);
37+
38+
}
39+
40+
}
41+
42+
```

0 commit comments

Comments
 (0)