이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
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... |