Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
using namespace std;
#define int long long
#define INF 99999999
typedef pair<int,int> pii;
typedef priority_queue<int> pque;
pii stand[10010]={};
pque que;
int A[100000]={},B[100000]={};
signed main() {
int N,L,P;
cin>>N;
for(int i=1;i<=N;i++) cin>>stand[i].first>>stand[i].second;
cin>>L>>P;
stand[0]=pii(0,0);
sort(stand,stand+N+1);
int pos=L,cnt=0;
for(int i=N;i>=0;i--){
int d=pos-stand[i].first;
while((P-d)<0){
if(que.empty()){
cout<<"-1"<<endl;
return 0;
}
P+=que.top();
que.pop();
cnt++;
}
P-=d;
pos=stand[i].first;
que.push(stand[i].second);
}
cout<<cnt<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment