From 5217ff35b6da09794a236750f06d2eba685e5d45 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Sat, 30 Aug 2025 17:44:39 +0900 Subject: [PATCH] =?UTF-8?q?[20250830]=20BOJ=20/=20G4=20/=20=EC=8A=A4?= =?UTF-8?q?=EC=B9=B4=EC=9D=B4=EB=9D=BC=EC=9D=B8=20=EC=89=AC=EC=9A=B4?= =?UTF-8?q?=EA=B1=B0=20/=20=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \354\211\254\354\232\264\352\261\260.md" | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 "0224LJH/202508/30 BOJ \354\212\244\354\271\264\354\235\264\353\235\274\354\235\270 \354\211\254\354\232\264\352\261\260.md" diff --git "a/0224LJH/202508/30 BOJ \354\212\244\354\271\264\354\235\264\353\235\274\354\235\270 \354\211\254\354\232\264\352\261\260.md" "b/0224LJH/202508/30 BOJ \354\212\244\354\271\264\354\235\264\353\235\274\354\235\270 \354\211\254\354\232\264\352\261\260.md" new file mode 100644 index 00000000..cc959a0f --- /dev/null +++ "b/0224LJH/202508/30 BOJ \354\212\244\354\271\264\354\235\264\353\235\274\354\235\270 \354\211\254\354\232\264\352\261\260.md" @@ -0,0 +1,55 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + static int cnt,ans; + static int[] arr; + + public static void main(String[] args) throws Exception { + init(); + process(); + print(); + + } + + public static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + cnt = Integer.parseInt(br.readLine()); + arr = new int[cnt]; + for (int i = 0; i < cnt; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + st.nextToken(); + arr[i] = Integer.parseInt(st.nextToken()); + } + ans = 0; + } + + public static void process(){ + PriorityQueue pq = new PriorityQueue<>(Collections.reverseOrder()); + for (int i = 0; i < cnt; i++) { + int height = arr[i]; + + while (!pq.isEmpty() && pq.peek() > height) { + pq.poll(); + ans++; + } + + if (height == 0) continue; + + if (pq.isEmpty() || pq.peek() != height) pq.add(height); + + + } + + ans += pq.size(); + } + + public static void print(){ + System.out.println(ans); + } + + +} +```