Advertisement
nikunjsoni

871

May 27th, 2021
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int minRefuelStops(int target, int startFuel, vector<vector<int>>& stations) {
  4.         int curMax = startFuel, stops=0, idx=0;
  5.         priority_queue<int> pq;
  6.        
  7.         for(stops=0; curMax<target; stops++){
  8.             while(idx<stations.size() && stations[idx][0] <= curMax)
  9.                 pq.push(stations[idx++][1]);
  10.             if(pq.empty()) return -1;
  11.             curMax += pq.top();
  12.             pq.pop();
  13.         }
  14.         return stops;
  15.     }
  16. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement