#C1457. Truck Loading Optimization
Truck Loading Optimization
Truck Loading Optimization
You are given P packages and T trucks. Each package has a weight and each truck has a maximum capacity. The goal is to load as many packages as possible onto the trucks without exceeding any truck's capacity. A package with weight \(w\) can only be loaded onto a truck with capacity \(c\) if \(w \leq c\). Each truck can carry at most one package.
Input Specification: The first line contains two integers \(P\) and \(T\). The second line contains \(P\) integers representing the weights of the packages. The third line contains \(T\) integers representing the capacities of the trucks.
Output Specification: Output a single integer representing the maximum number of packages that can be loaded onto the trucks.
Note: Both the list of packages and the list of trucks may be unsorted. A greedy algorithm that sorts both lists and then attempts to match the lightest packages with the smallest available trucks works well for this problem.
inputFormat
The input is read from stdin and has the following format:
P T w1 w2 ... wP c1 c2 ... cT
Where:
- P is the number of packages.
- T is the number of trucks.
- w1, w2, ..., wP are the weights of the packages.
- c1, c2, ..., cT are the capacities of the trucks. </p>
outputFormat
The output is a single integer written to stdout, representing the maximum number of packages that can be loaded without exceeding any truck's capacity.
## sample5 3
10 20 30 40 50
60 70 80
3