priority queue + binary search