Skip to content

Instantly share code, notes, and snippets.

@tina1998612
Last active October 23, 2016 03:46
Show Gist options
  • Save tina1998612/fda2c16b3a27c0af54495d10aa902fd5 to your computer and use it in GitHub Desktop.
Save tina1998612/fda2c16b3a27c0af54495d10aa902fd5 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
#define N 300000+5
#define ll long long
#define INF 2147483647
using namespace std;
int n,place;
ll hv,b,w;
typedef pair<ll,ll> P;
priority_queue<P> sml;
priority_queue<ll,vector<ll>,greater<ll> > bg;
int main(){
scanf("%d",&n); n--;
scanf("%I64d%I64d",&hv,&w);
place=1;
for(int i=0;i<n;i++){
scanf("%I64d%I64d",&b,&w);
if(b<=hv) sml.push(P(b,w));
else bg.push(w-b+1),place++;
}
while(!bg.empty() && bg.top()<=hv){
hv-=bg.top();
bg.pop();
while(!sml.empty() && hv<sml.top().first) {
bg.push(sml.top().second-sml.top().first+1);
sml.pop();
}
if(place>bg.size()+1) place=bg.size()+1;
}
printf("%d\n",place);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment