remove sliding window maximum and find k-th smallest element