单调队列
def solve(l, n, k):
index = []
for i in range(n):
while index and l[index[-1]] < l[i]:
index.pop(-1)
index.append(i)
while index and i - index[0] >= k:
index.pop(0)
print(index)
if i >= k - 1:
if i != n - 1:
print(l[index[0]], end = ' ')
else:
print(l[index[0]])
while True:
try:
n, k = map(int, input().split())
l = list(map(int, input().split()))
solve(l, n, k)
except EOFError:
break
京公网安备 11010502036488号