#include<iostream>
#include<set>
#include<vector>
#define SZ(X) ((int)(X).size())
using namespace std;
const int SIZE = 1 << 20;
int main() {
int n, k;
cin >> n >> k;
vector<int> x(n);
multiset<int> small, big; // big 維護前 k / 2 + 1 大的數,small 維護剩下的數
int need = k / 2 + 1;
for(int i = 0; i < n; i++) {
cin >> x[i];
big.insert(x[i]);
if(big.size() > need) {
small.insert(*big.begin());
big.erase(big.begin());
}
if(i >= k) {
if(small.find(x[i - k]) != small.end()) {
small.erase(small.find(x[i - k]));
} else {
big.erase(big.find(x[i - k]));
big.insert(*prev(small.end()));
small.erase(prev(small.end()));
}
}
if(i >= k - 1) cout << *big.begin() << (i + 1 < n ? ' ' : '\n');
}
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPHNldD4KI2luY2x1ZGU8dmVjdG9yPgojZGVmaW5lIFNaKFgpICgoaW50KShYKS5zaXplKCkpCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBTSVpFID0gMSA8PCAyMDsKaW50IG1haW4oKSB7CiAgICBpbnQgbiwgazsKICAgIGNpbiA+PiBuID4+IGs7CiAgICB2ZWN0b3I8aW50PiB4KG4pOwogICAgbXVsdGlzZXQ8aW50PiBzbWFsbCwgYmlnOyAvLyBiaWcg57at6K235YmNIGsgLyAyICsgMSDlpKfnmoTmlbjvvIxzbWFsbCDntq3orbfliankuIvnmoTmlbgKICAgIGludCBuZWVkID0gayAvIDIgKyAxOwogICAgZm9yKGludCBpID0gMDsgaSA8IG47IGkrKykgewogICAgICAgIGNpbiA+PiB4W2ldOwogICAgICAgIGJpZy5pbnNlcnQoeFtpXSk7CiAgICAgICAgaWYoYmlnLnNpemUoKSA+IG5lZWQpIHsKICAgICAgICAgICAgc21hbGwuaW5zZXJ0KCpiaWcuYmVnaW4oKSk7CiAgICAgICAgICAgIGJpZy5lcmFzZShiaWcuYmVnaW4oKSk7CiAgICAgICAgfQogICAgICAgIGlmKGkgPj0gaykgewogICAgICAgICAgICBpZihzbWFsbC5maW5kKHhbaSAtIGtdKSAhPSBzbWFsbC5lbmQoKSkgewogICAgICAgICAgICAgICAgc21hbGwuZXJhc2Uoc21hbGwuZmluZCh4W2kgLSBrXSkpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgYmlnLmVyYXNlKGJpZy5maW5kKHhbaSAtIGtdKSk7CiAgICAgICAgICAgICAgICBiaWcuaW5zZXJ0KCpwcmV2KHNtYWxsLmVuZCgpKSk7CiAgICAgICAgICAgICAgICBzbWFsbC5lcmFzZShwcmV2KHNtYWxsLmVuZCgpKSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYoaSA+PSBrIC0gMSkgY291dCA8PCAqYmlnLmJlZ2luKCkgPDwgKGkgKyAxIDwgbiA/ICcgJyA6ICdcbicpOwogICAgfQp9