#P3875. Pollution Spread: Counting Affected Communities

    ID: 17123 Type: Default 1000ms 256MiB

Pollution Spread: Counting Affected Communities

Pollution Spread: Counting Affected Communities

In a troubled town, some unscrupulous businessmen built factories which polluted the river. Many riverbank residents who drink from the contaminated river become ill. The government dispatched an inspector, Xiao Qiang, who obtained a pollution list from a geography expert. The list contains several polluted segments along the river. A polluted segment is represented by an open interval \( (l, r) \), meaning that if a community's water supply point \( x \) satisfies \( l < x < r \), then its residents are at risk.

You are given a list of polluted segments and a list of community water supply positions. Your task is to count the number of communities that are affected (i.e. for which there exists at least one polluted segment such that \( l < x < r \)).

Note: The endpoints of any interval are not included, so if a community's position equals \( l \) or \( r \), it is not considered affected.

inputFormat

The first line contains two integers \( n \) and \( m \) \( (1 \leq n, m \leq 10^5) \) representing the number of polluted segments and the number of communities, respectively.

The next \( n \) lines each contain two integers \( l \) and \( r \) (with \( l < r \)) describing a polluted segment, representing the open interval \( (l, r) \).

The last line contains \( m \) integers, each representing the coordinate \( x \) of a community's water supply point.

outputFormat

Output a single integer: the number of communities that are affected (i.e. the number of communities for which there is at least one polluted segment satisfying \( l < x < r \)).

sample

2 5
1 5
10 20
2 5 10 15 20
2