#C5594. Minimum Container Usage
Minimum Container Usage
Minimum Container Usage
You are given a list of gemstone weights and a list of container capacities. Your task is to determine the minimum number of containers needed to store all the gemstones.
For each container with capacity \(C\), the gemstones placed inside must satisfy the inequality \(\sum_{i} g_i \le C\), where \(g_i\) represents the weight of each gemstone in that container. You may rearrange the gemstones in any order.
If it is not possible to fit all the gemstones into the available containers under the given constraints, output -1.
inputFormat
The input is provided via standard input (stdin) in three lines:
- The first line contains two space-separated integers: (N) (the number of gemstones) and (M) (the number of containers).
- The second line contains (N) space-separated integers representing the weights of the gemstones.
- The third line contains (M) space-separated integers representing the capacities of the containers.
outputFormat
Output a single integer via standard output (stdout) which is the minimum number of containers used to store all the gemstones. If it is not possible, output -1.## sample
3 3
4 8 1
5 5 10
2