参考:❀
1 #include<iostream> 2 #include<cstdio> 3 #include<queue> 4 #include<algorithm> 5 using namespace std; 6 const int MAXN=2500+50; 7 struct rec 8 { 9 int a,b; 10 bool operator < (const rec& x) const 11 { 12 return a<x.a; 13 } 14 }; 15 16 rec cow[MAXN],sunscreen[MAXN]; 17 int C,L,ans=0; 18 19 int main() 20 { 21 scanf("%d%d",&C,&L); 22 for (int i=0;i<C;i++) scanf("%d%d",&cow[i].a,&cow[i].b); //a:min b:max 23 for (int i=0;i<L;i++) scanf("%d%d",&sunscreen[i].a,&sunscreen[i].b);//a:effect b:num 24 priority_queue< int,vector<int>,greater<int> > pque; 25 sort(cow,cow+C); 26 sort(sunscreen,sunscreen+L); 27 int j=0; 28 for (int i=0;i<L;i++) 29 { 30 while (j<C && cow[j].a<=sunscreen[i].a) 31 { 32 pque.push(cow[j].b); 33 j++; 34 } 35 while (!pque.empty() && sunscreen[i].b)//莫忘队列为空时也不执行 36 { 37 int temp=pque.top(); 38 pque.pop(); 39 if (temp<sunscreen[i].a) continue; 40 sunscreen[i].b--; 41 ans++; 42 } 43 } 44 cout<<ans<<endl; 45 return 0; 46 }