#K10131. Max Locations Visited
Max Locations Visited
Max Locations Visited
You are given two arrays. The first array represents the weights of packages and the second array represents the weight limits of different locations. Your task is to determine the maximum number of locations that can be visited by assigning each package to a location such that the package's weight is less than or equal to the location's weight limit.
Note: You should sort both arrays in non-decreasing order and then use a two-pointer greedy approach to pair packages with locations. Mathematically, given two arrays \(A\) and \(B\), you need to find the maximum number of pairs \((i, j)\) such that \(A[i] \le B[j]\) after sorting both arrays.
inputFormat
The input consists of three lines:
- The first line contains two integers \(n\) and \(m\): the number of packages and the number of locations.
- The second line contains \(n\) space-separated integers representing the weights of the packages. If \(n = 0\), this line will be empty.
- The third line contains \(m\) space-separated integers representing the weight limits at the locations. If \(m = 0\), this line will be empty.
outputFormat
Output a single integer indicating the maximum number of locations that can be visited.
## sample5 3
4 2 5 1 3
7 3 6
3