#K85552. Maximizing Parcels on Shelves
Maximizing Parcels on Shelves
Maximizing Parcels on Shelves
You are given two lists: one representing the weights of parcels and the other representing the capacities of shelves. Each shelf can hold at most one parcel. A parcel can be placed on a shelf if and only if its weight is less than or equal to the shelf's capacity. Your task is to determine the maximum number of parcels that can be assigned to the shelves.
Note: The lists may not be sorted. You need to design an efficient algorithm to maximize the number of parcels that can be placed on the shelves.
For example, given parcels [2, 3, 4, 5] and shelves [3, 4, 1, 2], the maximum number of parcels that can be placed is 3.
inputFormat
The input consists of four lines:
- The first line contains an integer
n
, representing the number of parcels. - The second line contains
n
space-separated integers, representing the weights of the parcels. - The third line contains an integer
m
, representing the number of shelves. - The fourth line contains
m
space-separated integers, representing the capacities of the shelves.
outputFormat
Output a single integer which is the maximum number of parcels that can be placed on the shelves.
## sample4
2 3 4 5
4
3 4 1 2
3
</p>