#K50542. Max Completed Tasks

    ID: 28887 Type: Default 1000ms 256MiB

Max Completed Tasks

Max Completed Tasks

You are given a set of n employees and m tasks. Each employee is characterized by two integers: the number of available hours Hi and the skill level Si.

Each task requires a certain amount of time Tj and a minimum skill level Rj to complete. An employee can complete a task if and only if:

\( T_j \leq H_i \quad\text{and}\quad R_j \leq S_i \)

Each employee can work on tasks sequentially using his/her available working hours. The tasks and employees are processed in a sorted order based on their skill levels (and available time in case of a tie). Your goal is to determine the maximum number of tasks that can be completed by optimally assigning tasks to the employees.

inputFormat

The input is read from standard input (stdin) and has the following format:

 n m
 H1 S1
 H2 S2
 ...
 Hn Sn
 T1 R1
 T2 R2
 ...
 Tm Rm

Here, the first line contains two integers: n (the number of employees) and m (the number of tasks). The next n lines each contain two integers representing the available hours Hi and the skill level Si of the i-th employee. The following m lines each contain two integers representing the required time Tj and required skill level Rj of the j-th task.

outputFormat

Output a single integer on standard output (stdout) — the maximum number of tasks that can be completed under the given constraints.

## sample
3 3
10 5
8 7
6 4
5 3
4 4
6 6
2