Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions Ukj0ng/202602/08 BOJ G3 크게 만들기.md
Original file line number Diff line number Diff line change
@@ -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<Integer> 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();
}
}
```