2500*2500直接排序暴力贪心
#include<iostream> #include<cstring> #include<algorithm> using namespace std; #define maxn 3000 struct ac{ int x,y; }a[maxn],b[maxn]; bool cmp(ac q,ac w){ return q.x>w.x; } int main(){ int n,m; cin>>n>>m; for(int j=1;j<=n;j++){ cin>>a[j].x>>a[j].y; } for(int k=1;k<=m;k++){ cin>>b[k].x>>b[k].y; } sort(a+1,a+1+n,cmp); sort(b+1,b+1+m,cmp); int ans=0; for(int j=1;j<=n;j++){ for(int k=1;k<=m;k++){ if(a[j].x>b[k].x) break; if(b[k].x>=a[j].x&&b[k].x<=a[j].y&&b[k].y>0){ ans++; b[k].y--; break; } } } cout<<ans<<endl; }