Skip to content

Commit 9210986

Browse files
authored
[20251118] BOJ / G5 / 옥상 정원 꾸미기 / 이준희
1 parent 0ab555f commit 9210986

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
public static void main(String[] args) throws Exception {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
int N = Integer.parseInt(br.readLine());
9+
10+
long answer = 0;
11+
Stack<Integer> stack = new Stack<>();
12+
13+
for (int i = 0; i < N; i++) {
14+
int height = Integer.parseInt(br.readLine());
15+
16+
while (!stack.isEmpty() && stack.peek() <= height) {
17+
stack.pop();
18+
}
19+
20+
answer += stack.size();
21+
22+
stack.push(height);
23+
}
24+
25+
System.out.println(answer);
26+
}
27+
}
28+
```

0 commit comments

Comments
 (0)