#include <iostream>
#include <string>
#include <deque>
#include <algorithm>

using namespace std;
int n,l;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    deque<pair<int, int>> dq;
    cin >> n >> l;
    for(int i=0; i<n; i++) {
        int x;
        cin >> x;
        while(!dq.empty() && dq.back().second>=x) {
            dq.pop_back();
        }

        dq.push_back({i,x});

        if(dq.front().first<=i-l) {
            dq.pop_front();
        }
        cout << dq.front().second << " ";
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: