Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int minRefuelStops(int target, int startFuel, vector<vector<int>>& stations) {
- int curMax = startFuel, stops=0, idx=0;
- priority_queue<int> pq;
- for(stops=0; curMax<target; stops++){
- while(idx<stations.size() && stations[idx][0] <= curMax)
- pq.push(stations[idx++][1]);
- if(pq.empty()) return -1;
- curMax += pq.top();
- pq.pop();
- }
- return stops;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement