This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
from typing import List
from bisect import bisect_right
def longest_nondec_subseq(arr: List[int]) -> int:
min_endings = []
for i in arr:
# bisect_right not left because it just has to be nondecreasing
pos = bisect_right(min_endings, i)
# standard LIS protocol
if pos == len(min_endings):
min_endings.append(i)
else:
min_endings[pos] = i
return len(min_endings)
pole_num, jump_height = [int(i) for i in input().split()]
poles = [int(input()) for _ in range(pole_num)]
poss_unchanged = []
for i, p in enumerate(poles):
if (i + 1) * jump_height >= p:
poss_unchanged.append((i + 1) * jump_height - p)
print(pole_num - longest_nondec_subseq(poss_unchanged))
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |