2024-11-01 08:49:12 +08:00

27 lines
820 B
Python

def 电梯调度():
当前位置, 请求数量 = map(int, input().split())
请求序列 = list(map(int, input().split()))
移动方向 = int(input())
大于当前位置 = [x for x in 请求序列 if x > 当前位置]
小于当前位置 = [x for x in 请求序列 if x < 当前位置]
等于当前位置 = [x for x in 请求序列 if x == 当前位置]
大于当前位置.sort()
小于当前位置.sort(reverse=True)
结果 = []
if 等于当前位置:
结果.extend(等于当前位置)
if 移动方向 == 1:
结果.extend(大于当前位置)
结果.extend(小于当前位置)
else:
结果.extend(小于当前位置)
结果.extend(大于当前位置)
print(' '.join(map(str, 结果)))
电梯调度()