목차

Rabbit Carrot

ps
링크acmicpc.net/…
출처BOJ
문제 번호27347
문제명Rabbit Carrot
레벨플래티넘 4
분류

LIS

시간복잡도O(nlogn)
인풋사이즈n<=200,000
사용한 언어Python 3.13
제출기록63864KB / 184ms
최고기록184ms
해결날짜2026/01/17

풀이

코드

"""Solution code for "BOJ 27347. Rabbit Carrot".

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

Tags: [lis]
"""

import sys
from teflib import seqtask


def main():
    N, M = [int(x) for x in sys.stdin.readline().split()]
    a = [int(sys.stdin.readline()) for _ in range(N)]

    seq = [0] + [a_i - i * M for i, a_i in enumerate(a, start=1)]
    lds_len = seqtask.longest_dec_subseq_length_by_first_elem(seq)[0]
    answer = N + 1 - lds_len

    print(answer)


if __name__ == '__main__':
    main()