Skip to content

Commit 6da06e3

Browse files
authored
Merge pull request #776 from AlgorithmWithGod/0224LJH
[20250830] BOJ / G4 / 스카이라인 쉬운거 / 이종환
2 parents 8b743ef + 5217ff3 commit 6da06e3

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
7+
static int cnt,ans;
8+
static int[] arr;
9+
10+
public static void main(String[] args) throws Exception {
11+
init();
12+
process();
13+
print();
14+
15+
}
16+
17+
public static void init() throws IOException {
18+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
19+
cnt = Integer.parseInt(br.readLine());
20+
arr = new int[cnt];
21+
for (int i = 0; i < cnt; i++) {
22+
StringTokenizer st = new StringTokenizer(br.readLine());
23+
st.nextToken();
24+
arr[i] = Integer.parseInt(st.nextToken());
25+
}
26+
ans = 0;
27+
}
28+
29+
public static void process(){
30+
PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
31+
for (int i = 0; i < cnt; i++) {
32+
int height = arr[i];
33+
34+
while (!pq.isEmpty() && pq.peek() > height) {
35+
pq.poll();
36+
ans++;
37+
}
38+
39+
if (height == 0) continue;
40+
41+
if (pq.isEmpty() || pq.peek() != height) pq.add(height);
42+
43+
44+
}
45+
46+
ans += pq.size();
47+
}
48+
49+
public static void print(){
50+
System.out.println(ans);
51+
}
52+
53+
54+
}
55+
```

0 commit comments

Comments
 (0)