LCC/Moose '20 Contest 1 S4 - Clowns and Shoes

View as PDF

Submit solution

Points: 15 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

There are N clowns, N pairs of shoes, and M shoe colours. Each clown has a favourite shoe colour f_i. Each clown also has a shoe size s_i, and can only wear shoes with size  t_j \geq s_i. Assuming every clown must be given a pair of shoes that they can wear, how many can get their favourite colour?

Input Specification

The first line will contain two integers N\ (1 \leq N \leq 2\cdot 10^5) and M\ (1 \leq M \leq 10^9).

The next N lines will contain 2 integers c_j\ (1 \leq c_j \leq M) and t_j\ (1 \leq t_j \leq 10^9), the colour and size of the j^{th} shoe respectively.

The next N lines will contain 2 integers f_i\ (1 \leq f_i \leq M) and s_i\ (1 \leq s_i \leq 10^9), the favourite colour and shoe size of the i^{th} clown respectively.

It is guaranteed that it is possible to distribute the shoes among the clowns such that each clown is given a pair of shoes that they can wear.

Output Specification

On one line you are to output one integer, the number of clowns who can wear shoes of their favourite color in a valid distribution.

Subtasks

Subtask 1 (5%)

N \leq 8

Subtask 2 (20%)

M \leq 2

Subtask 3 (75%)

No further constraints.

Sample Input

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

Sample Output

0

Comments

There are no comments at the moment.