#C4359. Plant Sunlight Placement
Plant Sunlight Placement
Plant Sunlight Placement
You are given N locations and M plants. Each location has a specific amount of sunlight, and each plant requires a minimum amount of sunlight to grow properly. A plant can be placed in a location only if the location's sunlight is at least the plant's requirement. Moreover, each location can host at most one plant.
The goal is to decide whether it is possible to assign each of the M plants to a distinct location from the N available locations such that for every plant, the following condition holds:
where \(A\) is the sorted list (in non-decreasing order) of sunlight values of the chosen locations, and \(B\) is the sorted list of minimum sunlight requirements of the plants. If \(M > N\), then it is impossible to place all plants.
Determine for each test case if it is possible to place all plants such that each plant gets the required sunlight. Print YES
if it is possible, otherwise print NO
.
inputFormat
The input is read from stdin and is structured as follows:
- The first line contains an integer T denoting the number of test cases.
- For each test case:
- The first line contains two integers N and M representing the number of locations and the number of plants respectively.
- The second line contains N integers, representing the sunlight available at each location.
- The third line contains M integers, representing the minimum sunlight requirements for each plant.
outputFormat
For each test case, output a single line to stdout containing either YES
if it is possible to place all the plants meeting their sunlight requirements, or NO
otherwise.
2
5 3
8 2 4 5 7
3 4 1
4 2
1 6 7 3
5 2
YES
NO
</p>