Skip to content

Commit 0e3c723

Browse files
authored
[20250721] BOJ / G4 / 스카이라인 쉬운거 / 이강현
1 parent ccdc286 commit 0e3c723

File tree

1 file changed

+35
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)