#include<bits/stdc++.h>
using namespace std;
int n,c,a[100005],s[100005],top=0;
inline int read()
{
int x=0;
char c=getchar();
while(c<'0'||c>'9') c=getchar();
while(c>='0'&&c<='9')
{
x=x*10+c-'0';
c=getchar();
}
return x;
}
int main()
{
n=read();c=read();
for(int i=1;i<=n;i++) a[i]=read();
for(int i=1;i<=n;i++)
{
if(top==c) cout<<s[top--]<<" ";
int t=a[i],j=i+1;
for(;j<i+c-top;j++) t=min(t,a[j]);
while(top&&s[top]<=t){cout<<s[top--]<<" ";t=min(t,a[j]);if(j<n) j++;}
if(t==a[i]) cout<<a[i]<<" ";
else s[++top]=a[i];
}
while(top) cout<<s[top--]<<" ";
}
如你所见,O(N^2)的算法居然没有 TLE 而是 WA 了,求调