- 스택의 마지막 수와 N자리 숫자의 i번째 수를 비교했을때 스택의 마지막 원소의 값이 더 작다면
pop
하고 N자리 숫자의 i번째 수를 스택에 넣어준다.
import sys
input = sys.stdin.readline
N, K = map(int, input().strip().split())
li = input().strip()
stack = []
t = K
for i in range(N):
while stack and t > 0 and stack[-1] < int(li[i]):
stack.pop()
t -= 1
stack.append(int(li[i]))
print(''.join(map(str, stack[:N-K])))