import sys
import bisect
def main():
data = sys.stdin.read().strip().split()
if not data:
return
# Parse input
N = int(data[0])
M = int(data[1])
T = list(map(int, data[2:2+M]))
A = list(map(int, data[2+M:2+2*M]))
# Build events: each event becomes (L, R)
events = []
for i in range(M):
L = T[i] - A[i]
R = T[i] + A[i]
events.append((L, R))
# Sort events by L ascending; if L is equal, sort by R descending.
events.sort(key=lambda x: (x[0], -x[1]))
# We now wish to compute the length of the longest strictly decreasing subsequence in R.
# Equivalently, compute the longest strictly increasing subsequence in x = -R.
lis = []
for L, R in events:
x = -R
pos = bisect.bisect_left(lis, x)
if pos == len(lis):
lis.append(x)
else:
lis[pos] = x
# The length of lis is the minimum number of hands S.
print(len(lis))
if __name__ == "__main__":
main()
Compilation message (stdout)
Compiling 'Arcade.py'...
=======
adding: __main__.pyc (deflated 37%)
=======
# | 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... |