from Third Algorithm Practical Skills Test PAST3J
from bisect import bisect_right
N, M = [int(x) for x in input().split()]
XS = [int(x) for x in input().split()]
scores = [0] * N
for x in XS:
# need to nagate to keep asc. order
# print("come", x)
i = bisect_right(scores, -x)
if i == N:
print(-1)
else:
print(i + 1)
scores[i] = -x
# print(scores)
This page is auto-translated from /nishio/PAST3J using DeepL. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. I'm very happy to spread my thought to non-Japanese readers.