题面
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/5d9f699a94befce4330832cdbede21d1.png)
代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
using namespace std;
struct Node
{
int index;
int num;
Node(int index, int num) :index(index), num(num) {};
};
deque<Node> q;
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) {
int num; cin >> num;
Node temp = Node(i, num);
if (!q.empty() && q.front().index < i - k + 1) q.pop_front();
while (!q.empty() && q.back().num < num) q.pop_back();
q.push_back(temp);
if (i >= k - 1) {
cout << q.front().num << endl;
}
}
return 0;
}