Deque<Integer> deque = new LinkedList<Integer>();
for (int i = 0; i < n; i++) {
//队列下标范围大于k就去掉队头
if (!deque.isEmpty() && i - deque.peekFirst() + 1 > k) deque.pollFirst();
//循环去掉<=arr[i]或者>=arr[i]的数
while (deque.isEmpty() && arr[i] <= arr[deque.peekLast()]) deque.pollLast();
//把当前这个数加入队列,无论大小,因为后面可能会用到
deque.offerLast(i);
//当队列下标范围>=k时,输出
if (i + 1 >= k) {
writer.write(Integer.toString(arr[deque.peekFirst()]));
writer.write(" ");
}
}