From 6a86b10d20f9b05c566fe22bc3d0cce10332fb62 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Sun, 8 Feb 2026 11:11:25 +0900 Subject: [PATCH] =?UTF-8?q?[20260208]=20BOJ=20/=20G3=20/=20=ED=81=AC?= =?UTF-8?q?=EA=B2=8C=20=EB=A7=8C=EB=93=A4=EA=B8=B0=20/=20=ED=95=9C?= =?UTF-8?q?=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \353\247\214\353\223\244\352\270\260.md" | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "Ukj0ng/202602/08 BOJ G3 \355\201\254\352\262\214 \353\247\214\353\223\244\352\270\260.md" diff --git "a/Ukj0ng/202602/08 BOJ G3 \355\201\254\352\262\214 \353\247\214\353\223\244\352\270\260.md" "b/Ukj0ng/202602/08 BOJ G3 \355\201\254\352\262\214 \353\247\214\353\223\244\352\270\260.md" new file mode 100644 index 00000000..5bd953ee --- /dev/null +++ "b/Ukj0ng/202602/08 BOJ G3 \355\201\254\352\262\214 \353\247\214\353\223\244\352\270\260.md" @@ -0,0 +1,54 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static final StringBuilder sb = new StringBuilder(); + private static Stack stack; + private static int N, K, count; + + public static void main(String[] args) throws IOException { + init(); + + bw.write(sb.toString() + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + + stack = new Stack<>(); + char[] input = br.readLine().toCharArray(); + + int i = 0; + + while (i < N) { + int n = input[i] - '0'; + + while (count < K && (!stack.isEmpty() && stack.peek() < n)) { + stack.pop(); + count++; + } + stack.push(n); + i++; + } + + while (count < K) { + stack.pop(); + count++; + } + + while (!stack.isEmpty()) { + sb.append(stack.pop()); + } + + sb.reverse(); + } +} +```