POJ 2786 Keep the Customer Satisfied 优先队列
----------
const int maxn=900000; const int maxm=10000; int n; struct Dat{ int v,lim; const bool operator<(const Dat& rhs) const{ return v<rhs.v; } }a[maxn]; bool cmp(Dat a,Dat b){ return a.lim<b.lim; } priority_queue<Dat>que; int main(){ while (~scanf("%d",&n)){ for (int i=0;i<n;i++) scanf("%d%d",&a[i].v,&a[i].lim); sort(a,a+n,cmp); int sum=0; int ans=0; while (!que.empty()) que.pop(); for (int i=0;i<n;i++){ que.push(a[i]); sum+=a[i].v; while (sum>a[i].lim){ Dat top=que.top(); que.pop(); sum-=top.v; ans++; } } printf("%d\n",n-ans); } return 0; }
----------