File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments