N, K = gets.split.take(2).map(&:to_i) WA = N.times.map{ gets.to_i } cargo = [] WA.each{|w| if w > 0 idx = cargo.bsearch_index{|v|v >= w} over_w = idx ? cargo.size - idx : 0 if over_w < K cargo[idx || cargo.size, 0] = w end # p "a" if cargo.sort != cargo else idx = cargo.bsearch_index{|v|v == -w} cargo.delete_at(idx) if idx end } p cargo.size