사용자 도구

사이트 도구


ps:problems:boj:2812

크게 만들기

ps
링크acmicpc.net/…
출처BOJ
문제 번호2812
문제명크게 만들기
레벨골드 4
분류

스택

시간복잡도O(n)
인풋사이즈n<=500,000
사용한 언어Python
제출기록36044KB / 168ms
최고기록144ms
해결날짜2022/01/18

풀이

코드

"""Solution code for "BOJ 2812. 크게 만들기".

- Problem link: https://www.acmicpc.net/problem/2812
- Solution link: http://www.teferi.net/ps/problems/boj/2812

Tags: [Stack]
"""

INF = float('inf')


def main():
    N, K = [int(x) for x in input().split()]
    num = input()

    stack = []
    removed_count = 0
    for ch in num:
        while stack and removed_count < K and stack[-1] < ch:
            stack.pop()
            removed_count += 1
        stack.append(ch)

    print(''.join(stack[:N - K]))


if __name__ == '__main__':
    main()

토론

댓글을 입력하세요:
U V J U C
 
ps/problems/boj/2812.txt · 마지막으로 수정됨: 2022/01/18 15:55 저자 teferi