//蒟蒻写的代码WA了,求指点
// Subtask #0 - #3 WA
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
int n, k, hed[2], til[2], que[2][maxn], ans[2][maxn], p[2][maxn];
void push(int x, int id) {
while (que[0][til[0]] >= x && til[0] >= hed[0]) til[0]--;
while (que[1][til[1]] <= x && til[1] >= hed[1]) til[1]--;
que[0][++til[0]] = x, que[1][++til[1]] = x;
p[0][til[0]] = id, p[1][til[1]] = id;
}
int read() {
int res = 0, f = 1; char ch = getchar();
while (!isdigit(ch)) f = ch == '-' ? -1 : f, ch = getchar();
while (isdigit(ch)) res = (res << 1) + (res << 3) + (ch & 15), ch = getchar();
return f * res;
}
int main() {
// freopen("", "r", stdin);
// freopen("", "w", stdout);
memset(que[0], 193, sizeof que[0]);
memset(que[1], 63, sizeof que[1]);
hed[1] = hed[0] = 1;
n = read(), k = read();
for (int i = 1; i <= n; i++) {
int x = read();
if (p[0][hed[0]] <= i - k) hed[0]++;
if (p[1][hed[1]] <= i - k) hed[1]++;
push(x, i);
ans[0][i] = que[0][hed[0]];
ans[1][i] = que[1][hed[1]];
}
for (int i = k; i <= n; i++) printf(i == n ? "%d\n" : "%d ", ans[0][i]);
for (int i = k; i <= n; i++) printf(i == n ? "%d\n" : "%d ", ans[1][i]);
return 0;
}
十分感谢