class Solution { public: int minRefuelStops(int target, int startFuel, vector>& stations) { sort(stations.begin(), stations.end()); priority_queue q; int step=0; for (int current_pos = startFuel, i = 0; current_pos < target; ++step) { while (i < stations.size() && current_pos >= stations[i][0]) q.push(stations[i++][1]); if (current_pos >= target) return step; if (q.empty()) return -1; current_pos += q.top(); q.pop(); } return step; } };