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 bisect import bisect_left
temp_num, max_cheating = [int(i) for i in input().split()]
temps = [int(i) for i in input().split()]
assert temp_num == len(temps)
pref_longest = []
min_endings = []
for i, t in enumerate(temps):
pos = bisect_left(min_endings, t)
pref_longest.append(pos + 1)
if pos == len(min_endings):
min_endings.append(t)
else:
min_endings[pos] = t
longest = 0
max_begins = []
for i in range(temp_num - 1, -1, -1):
t = temps[i]
# negative to keep the binary search happy
pos = bisect_left(max_begins, -t)
longest = max(longest, pref_longest[i] + pos)
insert_pos = bisect_left(max_begins, -t - max_cheating)
if insert_pos == len(max_begins):
max_begins.append(-t - max_cheating)
else:
max_begins[insert_pos] = -t - max_cheating
print(longest)
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |