//核心知识点:优先队列可以满足贪心算法里边记录每次做的值 即 “如果做就做最大的那个的值”
bool cmp(const std::pare<int,int> &a,const std::pare<int,int> &b){
return a.first > b.first;
}
class Solution {
public:
int get_mini_stop(int p,int l,std::vector<std::pare<int,int>>& stop){
int result =0;
//cmp:指定从小到大排 还是从大到小排
std::sort(stop.begin(),stop.end(),cmp);
stop.push_back(std::make_pare(0,0));
std::priority_queue q;
for(int i = 0;i <stop.size();i++){
int dis = l - stop[i].first;
while(!q.empty() && dis > p){
p += q.top();
q.pop();
result ++;
}
if(q.empty() && p < dis){
return -1;
}
p -= dis;
l = stop[i].first;
//更新二叉堆 其最大值是top
q.push(stop[i].second)
}
return result;
}
};