input:dream.in output:dream.out

Time Limits: 1000 ms Memory Limits: 262144 KB

Description

1565510767917

Input

Output

Sample Input

1
2
3
4
5
2 2
1 3
2 4
1
3

Sample Output

1
2

Data Constraint

Hint

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#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;
}