input:dream.in output:dream.out
Time Limits:
1000 ms Memory Limits: 262144 KB Detailed Limits
1 #include<bits/stdc++.h> 2 using namespace std; 3 struct A 4 { 5 long l,r; 6 bool operator < (A w) const 7 { 8 return r>w.r; 9 } 10 }b[200010]; 11 priority_queue<A>q; 12 long n,m,a[200010],now=1,tot=0,ans=0; 13 bool ss (A t1,A t2) 14 { 15 return t1.l<t2.l; 16 } 17 int main() 18 { 19 freopen("dream.in","r",stdin); 20 freopen("dream.out","w",stdout); 21 scanf("%ld %ld",&n,&m); 22 for(int i=1;i<=n;i++) scanf("%ld %ld",&b[i].l,&b[i].r); 23 for(int i=1;i<=m;i++) scanf("%ld",&a[i]); 24 sort(b+1,b+n+1,ss); 25 sort(a+1,a+m+1); 26 for(int i=1;i<=m;i++) 27 { 28 while(b[now].l<=a[i]) 29 { 30 q.push(b[now]); 31 now++;tot++; 32 } 33 if(!tot) continue; 34 A tmp=q.top();q.pop(); 35 tot--; 36 while(tmp.r<a[i]&&tot) 37 { 38 tmp=q.top();q.pop();tot--; 39 } 40 if(tmp.r>=a[i]) ans++; 41 } 42 printf("%ld",ans); 43 return 0; 44 }