Use Standard priority queues give largest elements first. Pairs compare lexicographically, so largest first element wins. If you want smallest first, negate priorities: Dijkstra's algorithm uses this pattern with Understanding this concept deeply will help you write better code.
Practice with examples until the pattern becomes automatic. Review earlier sections if anything is unclear. Building on solid foundations makes advanced topics easier.