#K6086. Notebook Allocation

    ID: 31180 Type: Default 1000ms 256MiB

Notebook Allocation

Notebook Allocation

You are given K notebooks and N participants. Each notebook has a certain number of pages and each participant requires a notebook with at least a specified number of pages. Your task is to determine whether it is possible to allocate a distinct notebook to each participant such that the number of pages in the notebook is at least the number of pages requested by the participant.

More formally, you are provided with two arrays:

  • P: An array of K integers, where each integer represents the number of pages in the corresponding notebook.
  • Q: An array of N integers, where each integer represents the minimum number of pages required by a participant.

Determine if there exists an assignment of notebooks to participants such that for every participant, the assigned notebook has at least as many pages as they require.

The allocation strategy that works is to sort both arrays in non-decreasing order and then match the largest available notebook with the participant who has the highest requirement, the second largest with the second highest requirement, and so on. Mathematically, if we denote the sorted arrays by \(P'\) and \(Q'\), then the condition for successful allocation is:

\[ P'_{K-i} \geq Q'_{N-i} \quad \text{for all } 1 \leq i \leq N, \]

If K < N, then allocation is impossible.

inputFormat

The first line contains two integers K and N representing the number of notebooks and participants respectively. The second line contains K space-separated integers where each integer represents the number of pages in a notebook. The third line contains N space-separated integers representing the pages required by each participant.

outputFormat

Output a single word: "Yes" if it is possible to allocate the notebooks such that every participant receives a notebook with at least the required pages, otherwise output "No".## sample

5 4
300 500 200 400 600
250 450 100 500
Yes