Q, K = gets.split.map &:to_i a = [] size = 0 $<.map{|s| if s[/^1 /] v = $'.to_i a[a.bsearch_index{|n|n>v}||a.size, 0] = v size += 1 else if size < K p -1 else size -= 1 p a.delete_at(K-1) end end }