Rohan and Infinite Space

3.3

23 votes
Easy-Medium
Problem

Rohan is moving in a 1-dimensional infinite space. In that space, the marking are done on the integeral points only. It is similar to an integer marked number line. There are several lines in that space, these lines may overlap. You are also given some points in space.

Line is denoted by 2 integers - x and y, where xy, and it covers the points x, x+1, ... , y-1, y. Point is denoted by a single integer z. Point z is said to be intersecting with line [x, y] iff xzy.

You can make pair of a point and line if point is intersecting with line. Each point and line can be part of at most one pair.

Given all the lines and points you have to maximize the number of pairs.

Input Format

First line contains integer n, denoting number of lines
Next n lines of input, contains two space separated integers x and y, denoting a single line Next line contains integer m, denoting number of points Next m lines of input, contains a single integer z which denotes a single point

Output Format

Output a single integer, which is answer to the problem

Constraints

  • 1 ≤ n, m ≤ 100000
  • 1 ≤ x, y, z ≤ 109
  • xy
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation
  • Point 7 will be assigned to line [1, 7]
  • Point 8 will be assigned to line [1, 10]
    Only 2 pairs can be formed, therefore result is 2
Editor Image

?