Advertisement
serega1112

Superminimum

Dec 25th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1. from collections import deque
  2.  
  3. n, k = map(int, input().split())
  4. nums = list(map(int, input().split()))
  5.  
  6. q = deque()
  7. res = []
  8.  
  9. for i, num in enumerate(nums):
  10.     while q and num < nums[q[-1]]:
  11.         q.pop()
  12.     q.append(i)
  13.     if i >= k-1:
  14.         res.append(str(nums[q[0]]))
  15.         if q[0] == i - k + 1:
  16.             q.popleft()
  17.  
  18. print(' '.join(res))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement