#include using namespace std; int nn, zhe, a[1000001] = { 0 }; int tou = 0, wei = 0, f[1000001] = { 0 }, pai[1000001] = { 0 }; int main() { cin >> nn >> zhe; for (int i = 1; i <= nn; i++) { cin >> a[i]; } for (int i = 1; i <= nn; i++) { //cout << f[i - 1] << pai[i - 1] << endl; while (tou < wei && i - pai[tou] >= zhe) { tou++; } while (tou < wei && f[wei-1] > a[i]) { wei--; } f[wei] = a[i]; pai[wei++] = i; if (i >= zhe) { cout << f[tou] << " "; } } cout<= zhe) { tou++; } while (tou < wei && f[wei-1] < a[i]) { wei--; } f[wei] = a[i]; pai[wei++] = i; if (i >= zhe) { cout << f[tou] << " "; } } }