Slalom
Time limit1sMemory limit128 MB
Given gate pairs at increasing depths and S vertical speeds, find the smallest speed that lets a skier move horizontally fast enough to pass through every gate, and output it or IMPOSSIBLE.
- Level
Medium7 of 10
- Topics
- Binary search, Math, Greedy, Implementation
- Solved
- No attempts yet
Problem
You are competing in a ski slalom and need to choose the best pair of skis for the race. The course consists of pairs of gates. Each pair has a left gate and a right gate, with the right gate exactly metres to the right of the corresponding left gate; you may never pass to the left of a left gate nor to the right of a right gate. The -th pair of gates lies at vertical distance down the hill, and the horizontal position of its left gate is (so its right gate is at ). Every gate is farther down the hill than the previous one, i.e. for all .
You may pick one of pairs of skis; the -th pair has speed . If you use the skis with speed , you descend at a constant vertical velocity of metres per second. Separately, at any moment you may move horizontally at a speed of at most metres per second. You may start and finish at any horizontal positions.
Determine which pair of skis lets you complete the course, passing through every gate, in the shortest time.
Input
The first line contains three integers , , and , separated by spaces, with , , and .
Each of the next lines contains two integers and : the horizontal and vertical positions of the -th left gate, with .
The next line contains an integer , the number of ski pairs, with .
Each of the next lines contains one integer , the speed of the -th pair of skis, with .
Output
If no pair of skis can complete the course, print IMPOSSIBLE. Otherwise, print the vertical speed of the pair of skis that completes the course in the shortest time.