#K9046. Task Assignment Problem

    ID: 37757 Type: Default 1000ms 256MiB

Task Assignment Problem

Task Assignment Problem

You are given a set of n students along with their respective skill levels and m tasks, each with a required skill range represented by two integers: the minimum and maximum acceptable skill levels. Your task is to determine whether it is possible to assign each task to a different student such that the student’s skill level falls within the task’s required range (inclusive).

Note: Each student can be assigned to at most one task, and every task must be assigned to exactly one student for a valid assignment.

The constraints are as follows:

  • The first line of input consists of two integers: n the number of students and m the number of tasks.
  • The second line contains n integers representing the skill levels of the students.
  • The next m lines each contain two integers denoting the minimum and maximum required skill levels for a task.

Determine whether an assignment exists such that each task is matched with a distinct student whose skill level fits the task's requirement. Output YES if such an assignment exists; otherwise, output NO.

The problem can be formalized with the following condition: $$ \forall\, task\; (l_i \leq s_j \leq r_i) $$ where \(l_i\) and \(r_i\) are the lower and upper bounds for task \(i\), and \(s_j\) is the skill level of the student assigned to task \(i\).

inputFormat

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

 n m
 s1 s2 ... sn
 l1 r1
 l2 r2
 ...
 lm rm

Where:

  • n is the number of students.
  • m is the number of tasks.
  • s1 s2 ... sn are the skill levels of the students.
  • Each of the following m lines contains two integers l and r indicating the minimum and maximum acceptable skill levels for a task.

outputFormat

Output a single line to the standard output (stdout) containing either YES or NO. YES indicates that it is possible to assign each task to a suitable student, and NO indicates that it is not.

## sample
6 6
3 7 5 6 9 8
1 4
3 5
5 7
7 9
5 9
6 8
YES