#K83997. Minimum Number of Teams Required for Patrol
Minimum Number of Teams Required for Patrol
Minimum Number of Teams Required for Patrol
You are given \(n\) zones and \(m\) available teams. Each zone has a difficulty rating and each team has an energy level. A team can patrol a zone if and only if its energy level is at least as high as the difficulty rating of that zone.
Each team can patrol at most one zone, and each zone must be patrolled by exactly one team. Your task is to determine the minimum number of teams required to patrol all the zones. Since exactly one team is needed for each zone that can be patrolled, the answer will be \(n\) if a valid assignment is possible; otherwise, return \(-1\) if it is impossible to assign teams to all zones.
Note: The input is given via standard input and the answer must be printed to standard output.
inputFormat
The input consists of three lines:
- The first line contains two space-separated integers \(n\) and \(m\), representing the number of zones and the number of available teams respectively.
- The second line contains \(n\) space-separated integers, where the \(i\)-th integer denotes the difficulty rating of the \(i\)-th zone.
- The third line contains \(m\) space-separated integers, where the \(j\)-th integer denotes the energy level of the \(j\)-th team.
outputFormat
Output a single integer: the minimum number of teams required to patrol all zones (which is \(n\) if every zone can be patrolled) or \(-1\) if it is impossible.
## sample3 5
4 2 7
5 4 8 6 3
3