Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## ac代码！

Posted by mc77xy at 2020-02-12 12:36:27 on Problem 2431
```#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
int l,p,n;
pair<int,int>pa[10005];
bool cmp(pair<int,int> a,pair<int,int> b){
return a.first<b.first;
}
void solve(){
pa[n].first=l;
pa[n].second=0;
n++;
priority_queue<int>que;
int ans=0,pos=0,tank=p;
for(int i=0;i<n;i++){
int d=pa[i].first-pos;
while(tank-d<0){
if(que.empty()){
puts("-1");
return;
}
tank+=que.top();
que.pop();
ans++;
}
tank-=d;
pos=pa[i].first;
que.push(pa[i].second);
}
printf("%d\n",ans);
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d%d",&pa[i].first,&pa[i].second);
scanf("%d%d",&l,&p);
for(int i=0;i<n;i++)	pa[i].first=l-pa[i].first;
sort(pa,pa+n,cmp);
solve();
}```

Followed by: