Keeps minimum element on top
PriorityQueue < Pair > q = new PriorityQueue < > ( new Comparator < Pair > ( ) { public int compare ( Pair p1 , Pair p2 ) { if ( p1 . first == p2 . first ) { return p1 . second - p2 . second ; } return p1 . first - p2 . first ; } } ) ;