Hikers on markers along a route must take turns stepping forward so that neighbours stay within distance B and everyone keeps their personal space; output the lexicographically smallest order in which all reach the end, or impossible.
Hard8GreedySimulationImplementationNo attempts yetTime limit4sMemory limit512 MBA hiking club runs a time trial along a single route. The route has P marker points, marker i sits di metres from the start, and d1=0. The slow part of this sport is the pathfinding, so once a hiker knows where to go next, the walk itself takes no time at all.
K hikers are on the route. Hiker i stands on marker Vi and needs Ai metres of personal space. Two rules hold at every moment.
The hikers move one at a time. A single move takes one hiker from the marker they stand on to the next marker and finishes instantly, so nobody is ever between two markers. Both rules hold again after every move.
A hiker who reaches marker P has finished the route and leaves it at once. From that moment the two rules ignore that hiker, so a move onto marker P is always allowed. A hiker who stands on marker P at the start has already finished and never moves.
Work out the order in which the hikers move so that all of them finish the route.
The starting arrangement obeys both rules. A hiker who starts on marker P has already finished and is left out of that check.
If the hikers cannot all reach marker P without breaking a rule, print impossible.
Otherwise print the hiker numbers in the order they move, separated by single spaces, on one line. Every correct answer has the same length ∑i=1K(P−Vi), so print the lexicographically smallest one. Compare two answers one position at a time; the answer with the smaller number at the first position where they differ comes first.