#K9366. Max Distance Between Powered Lampposts
Max Distance Between Powered Lampposts
Max Distance Between Powered Lampposts
You are given M lampposts positioned on a number line and C batteries. Each lamppost requires a certain power demand to be lit, and each battery has a fixed capacity. A battery can power a lamppost if and only if its capacity is greater than or equal to the lamppost's required demand.
Your task is to determine whether it is possible to power all the lampposts by assigning batteries appropriately. If so, compute the maximum distance between any two lampposts, which is given by \(\max(positions) - \min(positions)\). Otherwise, output "Not Possible".
Note: All input should be read from standard input and all output should be written to standard output.
inputFormat
The input consists of four lines:
- The first line contains two integers M and C separated by a space, where M is the number of lampposts and C is the number of batteries.
- The second line contains M space-separated integers representing the positions of the lampposts.
- The third line contains M space-separated integers representing the power demands of the lampposts.
- The fourth line contains C space-separated integers representing the capacities of the batteries.
outputFormat
If it is possible to power all lampposts, output the maximum distance between any two lampposts (i.e. the difference between the largest and smallest positions). Otherwise, output the string "Not Possible".
## sample4 5
-10 0 15 20
8 5 7 6
10 12 8 5 7
30