#C11864. Interview Scheduling

    ID: 41227 Type: Default 1000ms 256MiB

Interview Scheduling

Interview Scheduling

In this problem, you are given the available time intervals of a set of applicants as well as the available time intervals of a set of interviewers. For each applicant, at least one preferred time interval is provided. Similarly, each interviewer has one or more available intervals during which they can conduct an interview. An interview can be scheduled if there exists a time interval from an applicant that is completely covered by one of the interviewer's available intervals. Furthermore, each applicant can be interviewed at most once and each interviewer can conduct at most one interview.

Formally, for an applicant with a time interval [a,b][a, b] and an interviewer with an available slot [c,d][c, d], an interview can be scheduled if and only if: [ c \leq a \quad \text{and} \quad b \leq d, ]

Your task is to determine the maximum number of interviews that can be scheduled under these constraints.

inputFormat

The input is given via standard input (stdin) and has the following format:

  • The first line contains two integers (n) and (m), where (n) is the number of applicants and (m) is the number of interviewers.
  • The next (n) lines each describe an applicant. Each of these lines begins with an integer (k) (the number of available time intervals for the applicant), followed by (2\times k) integers representing the intervals. Each interval is given by two integers (start) and (end), meaning the applicant is available from time (start) to time (end) (inclusive of start and end as boundaries for scheduling).
  • The following (m) lines each describe an interviewer. Each line begins with an integer (l) (the number of available slots for the interviewer), followed by (2\times l) integers representing the available intervals (each given as a pair (start) and (end)).

Note: It is guaranteed that all time values are integers.

outputFormat

Output a single integer to standard output (stdout): the maximum number of interviews that can be scheduled.## sample

3 2
2 9 11 13 15
1 10 12
3 14 16 17 19 20 22
2 9 12 14 18
1 10 13
2