Skip to content

Commit fc5fa2d

Browse files
authored
Merge pull request #1991 from AlgorithmWithGod/LiiNi-coder
[20260304] BOJ / G4 / 스카이라인 쉬운거 / 이인희
2 parents a2c6654 + c56fa56 commit fc5fa2d

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
```java
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
import java.util.ArrayDeque;
6+
import java.util.StringTokenizer;
7+
8+
public class Main{
9+
public static void main(String[] args)throws IOException{
10+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
int N = Integer.parseInt(br.readLine());
12+
ArrayDeque<Integer> stack = new ArrayDeque<Integer>();
13+
14+
int answer = 0;
15+
for(int i=0;i<N;i++){
16+
StringTokenizer st = new StringTokenizer(br.readLine());
17+
int x = Integer.parseInt(st.nextToken());
18+
int h = Integer.parseInt(st.nextToken());
19+
20+
while(!stack.isEmpty()){
21+
if(stack.peek() <= h) break;
22+
stack.pop();
23+
answer++;
24+
}
25+
26+
27+
if(h==0) continue;
28+
29+
if(stack.isEmpty() || stack.peek()<h){
30+
stack.push(h);
31+
}
32+
}
33+
34+
answer += stack.size();
35+
System.out.println(answer);
36+
br.close();
37+
}
38+
}
39+
```

0 commit comments

Comments
 (0)