arr = Array.from(new Array(4)).map(x => readline()).join(' ').split(' ').map(x => parseInt(x)) m = arr[0],n = arr[1] while (arr.length < n * 2 + m + 2){ arr.push(arr[arr.length - 1]) } h = Array.from(new Array(n)).map((x,y) => [arr[y + 2],arr[y + n + 2]]).sort((x,y) => x[1] > y[1] ? 1 : -1) p = Array.from(new Array(m)).map((x,y) => arr[y + n * 2 + 2]) n = 0 while (n < h.length){ n ++ while (n < h.length && h[n][0] <= h[n - 1][0]){ h.splice(n,1) } } for (var i = 0; i < m ; i ++){ t = h.filter(x => x[1] <= p[i]) print(t.length == 0 ? -1 : t[t.length -1][1]) } 将上面代码用python实现
时间: 2024-04-15 14:27:30 浏览: 87
javascript中new Array()和var arr=[]用法区别
你可以使用以下代码将上述 JavaScript 代码转换为 Python 代码:
```python
arr = [int(x) for x in input().split()]
m, n = arr[0], arr[1]
while len(arr) < n * 2 + m + 2:
arr.append(arr[-1])
h = [[arr[y + 2], arr[y + n + 2]] for y in range(n)]
h.sort(key=lambda x: x[1])
p = [arr[y + n * 2 + 2] for y in range(m)]
n = 0
while n < len(h):
n += 1
while n < len(h) and h[n][0] <= h[n - 1][0]:
h.pop(n)
for i in range(m):
t = [x for x in h if x[1] <= p[i]]
print(-1 if len(t) == 0 else t[-1][1])
```
请注意,这只是简单地将 JavaScript 代码转换为 Python 代码,可能需要根据实际情况进行进一步调整。
阅读全文