A group is on a journey together when they reach a crocodile-infested river. They all want to cross to the other side of the river, but there is no bridge, and none of the group can swim, nor are they crocodile-proof. Their only hope is to hop on the rocks on the river, which are miraculously positioned in a straight line. The position of the rocks are measured from the start location, assuming that the group starts at location zero. The opposite riverbank can be treated as the final rock to jump to.
Each member of the group can jump a different maximum distance and will go as far as they can for each jump. Can the whole group make it to the other side of the river? What is the smallest number of jumps each member of the group needs to take to reach the other side of the river?
Your program should output the minimum number of jumps needed for each group member, or -1
if it is not possible for that member to reach the other side of the river.
The input of your program should be:
A positive integer, n
, representing the number of rocks (including the opposite riverbank).
n
distinct, positive integers in increasing order that represent the locations of the rocks.
A positive integer, m
, representing the number of group members.
m
number of input lines, each containing the group member’s full name, and their maximum jump distance.
The output of your program should be:
Each group member’s name, and the number of jumps needed, or -1
if it is not possible for that group member to reach the other side of the river. The group members should be output in input order.
At the end, your program should state whether or not the whole group can make it to the other side, and list out who needs to improve their jumping skills.