input:dream.in output:dream.out

Time Limits: 1000 ms Memory Limits: 262144 KB

Description

1565510767917

Input

Output

Sample Input

2 2
1 3
2 4
1
3

Sample Output

2

Data Constraint

Hint

Code

#include<bits/stdc++.h>
using namespace std;
struct A
{
long l,r;
bool operator < (A w) const
{
return r>w.r;
}
}b[200010];
priority_queue<A>q;
long n,m,a[200010],now=1,tot=0,ans=0;
bool ss (A t1,A t2)
{
return t1.l<t2.l;
}
int main()
{
freopen("dream.in","r",stdin);
freopen("dream.out","w",stdout);
scanf("%ld %ld",&n,&m);
for(int i=1;i<=n;i++) scanf("%ld %ld",&b[i].l,&b[i].r);
for(int i=1;i<=m;i++) scanf("%ld",&a[i]);
sort(b+1,b+n+1,ss);
sort(a+1,a+m+1);
for(int i=1;i<=m;i++)
{
while(b[now].l<=a[i])
{
q.push(b[now]);
now++;tot++;
}
if(!tot) continue;
A tmp=q.top();q.pop();
tot--;
while(tmp.r<a[i]&&tot)
{
tmp=q.top();q.pop();tot--;
}
if(tmp.r>=a[i]) ans++;
}
printf("%ld",ans);
return 0;
}