From 0e3c7236efbc0fce8c19e7a60ed7e65ccc12385c Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Mon, 21 Jul 2025 20:39:11 +0900 Subject: [PATCH] =?UTF-8?q?[20250721]=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=EA=B0=95=ED=98=84?= 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" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "lkhyun/202507/21 BOJ G4 \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/lkhyun/202507/21 BOJ G4 \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/lkhyun/202507/21 BOJ G4 \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..fddbbc18 --- /dev/null +++ "b/lkhyun/202507/21 BOJ G4 \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,35 @@ +```java +import java.util.*; +import java.io.*; + +public class Main{ + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N; + static int ans = 0; + public static void main(String[] args) throws Exception { + N = Integer.parseInt(br.readLine()); + + ArrayDeque stk = new ArrayDeque<>(); + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + int x = Integer.parseInt(st.nextToken()); + int y = Integer.parseInt(st.nextToken()); + + while(!stk.isEmpty() && stk.peek() > y){ + stk.pop(); + ans++; + } + if(stk.isEmpty() && y > 0){ + stk.push(y); + }else if(!stk.isEmpty() && stk.peek() < y){ + stk.push(y); + } + } + ans += stk.size(); + bw.write(ans + "\n"); + bw.close(); + } +} +```