#include <iostream>
#include <stack>
using namespace std;
int main(){
int n,c,a;
stack<int> s;
cin>>n>>c;
int countt=0;
for (int i=0;i<n;i++){
countt++;
cin>>a;
while (!s.empty() && a>s.top() || countt==c+1) {
cout<<s.top()<<" ";
s.pop();
countt--;
}
s.push(a);
}
while (!s.empty()){
cout<<s.top()<<" ";
s.pop();
}
return 0;
}
思路类似单调队列(?