A resupply mission has just delivered n cargo pods to an orbital station, each pod holding a certain number of ration units. Mission control wants to consolidate every ration unit into as few of the station's storage lockers as possible, since each activated locker draws a fixed amount of power regardless of how full it ends up -- ration units can be freely repackaged and split across any lockers you decide to activate, so only the total capacity of the lockers you choose matters. Given the ration counts held by the pods and the capacity of every locker on the station, determine the minimum number of lockers that must be activated so that every ration unit can be stored somewhere.
n, the number of cargo pods.n space-separated integers, the ration count held by each pod.m, the number of storage lockers on the station.m space-separated integers, the unit capacity of each locker.Print a single integer: the minimum number of lockers that must be activated so that their combined capacity is at least the total number of ration units across all pods.
Example 1
Input
3 1 3 2 3 4 8 2
Expected
1
Explanation
The pods hold a total of 1 + 3 + 2 = 6 ration units. The largest single locker has capacity 8, which alone is already at least 6, so activating just that one locker is enough. The answer is 1.
Example 2
Input
2 5 5 4 2 4 2 7
Expected
2
Explanation
The pods hold a total of 5 + 5 = 10 ration units. The largest locker (capacity 7) alone is not enough since 7 < 10. Adding the next largest locker (capacity 4) gives 7 + 4 = 11 >= 10, so two lockers suffice and no single locker does. The answer is 2.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →