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(); + } +} +```