优先队列的使用
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
#include <utility>
#define maxn 10005
using namespace std;
pair<int, int> a[maxn];
int main(){
int n,l,p;
int i,j,k;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d%d",&a[i].first,&a[i].second);
}
scanf("%d%d",&l,&p);
a[n].first=l;
a[n].second=0;
for(i=0;i<n;i++){
a[i].first=l-a[i].first;
}
n++;
sort(a,a+n);
priority_queue<int> q;
int ans=0,pos=0,tank=p,distance;
for(i=0;i<n;i++){
distance=a[i].first-pos;
//printf("%d\n",a[i].first);
while(tank-distance<0){
if(q.empty()){
printf("-1\n");
return 0;
}
tank+=q.top();
q.pop();
ans++;
}
tank-=distance;
pos=a[i].first;
q.push(a[i].second);
}
printf("%d\n",ans);
return 0;
}