목차

병사 배치하기

ps
링크acmicpc.net/…
출처BOJ
문제 번호18353
문제명병사 배치하기
레벨실버 2
분류

LIS

시간복잡도O(nlogn)
인풋사이즈n<=2000
사용한 언어Python
제출기록32928KB / 72ms
최고기록56ms
해결날짜2022/02/27

풀이

코드

"""Solution code for "BOJ 18353. 병사 배치하기".

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

Tags: [LIS]
"""

import bisect


def main():
    N = int(input())  # pylint: disable=unused-variable
    nums = [int(x) for x in input().split()]

    arr = []
    for num in reversed(nums):
        pos = bisect.bisect_left(arr, num)
        if pos == len(arr):
            arr.append(num)
        else:
            arr[pos] = num

    print(N - len(arr))


if __name__ == '__main__':
    main()