Title Description
There are some sections, there are some points.
Asked the smallest k such that k arbitrarily selected intervals, each point can match the interval, an interval only match once.
answer
Consider for every point, we have \ (x \) intervals contain it, then the answer is a lower bound \ (the n-1-the X-+ \) .
But this does not take into account a case where two points of the matched segment.
From left to right we do, not to a point, put the right end of the leftmost deleted legitimate range, can prove which is the lower bound and can be reached.
Code
#include<bits/stdc++.h>
using namespace std;
#define N 100002
typedef long long ll;
int c[N],n,m;
int cnt;
inline ll rd(){
ll x=0;char c=getchar();bool f=0;
while(!isdigit(c)){if(c=='-')f=1;c=getchar();}
while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
return f?-x:x;
}
struct node{
int l,r;
inline bool operator <(const node &b)const{
return r>b.r;
}
}a[N];
priority_queue<node>q;
inline bool cmp(node a,node b){
if(a.l!=b.l)return a.l<b.l;
return a.r>b.r;
}
inline void solve(){
while(!q.empty())q.pop();
n=rd();m=rd();
for(int i=1;i<=n;++i){
a[i].l=rd();a[i].r=rd();
}
for(int i=1;i<=m;++i)c[i]=rd();
sort(c+1,c+m+1);
sort(a+1,a+n+1,cmp);
int p=0;
int ans=0;
for(int i=1;i<=m;++i){
while(p<n&&a[p+1].l<=c[i])p++,q.push(a[p]);
while(!q.empty()&&q.top().r<c[i])q.pop();
ans=max(ans,n-(int)q.size()+1);if(q.size())q.pop();
}
++cnt;
if(ans>n)printf("Case #%d: IMPOSSIBLE!\n",cnt);
else printf("Case #%d: %d\n",cnt,ans);
}
int main(){
int T=rd();
while(T--)solve();
return 0;
}