priority queue solution too slow