#BS0000373. Chọn ván trượt tuyết (Slalom 2)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chọn ván trượt tuyết (Slalom 2)
Slalom 2
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
A ski race has pairs of gates. Pair lies at downhill distance metres; its left post has horizontal coordinate and its right post is metres farther right. Cross every pair in order at a horizontal coordinate in , including the endpoints. Among pairs of skis, pair gives constant downhill speed metres per second. You may move sideways in either direction at speed at most metres per second. Your initial and final horizontal positions are unrestricted. Select skis allowing all gates to be passed in the shortest time.

Input
The first line contains integers . Each of the next lines contains integers . The next line contains integer . Each of the following lines contains integer .
Output
Print the greatest integer speed among skis that can pass every gate. If none is feasible, print IMPOSSIBLE.
Subtasks
- Subtask 1 (20 points): ; ; ; (); ; (). For every , .
- Subtask 2 (30 points): ; ; ; (); ; (). For every , .
- Subtask 3 (50 points): ; ; ; (); ; (). For every , .
Examples
Input
3 2 3
1 1
5 2
1 3
3
3
2
1
Output
2
Explanation
The intervals are . Speed 2 allows 0.5 seconds per transition and 1 metre of lateral movement. Positions 4,5,4 are feasible. Speed 3 only allows metre, too little for the second gate.
Input
3 2 3
1 1
5 2
1 3
1
3
Output
IMPOSSIBLE
Explanation
Only speed 3 is offered. The first two gates are at least 1 metre apart horizontally, beyond the allowed metre.
Input
1 1 3
1 1
3 2
5 3
2
1
2
Output
IMPOSSIBLE
Explanation
The three intervals are . At speed 1 total lateral movement is at most 2 metres between the first and last gate, less than the required 3. Speed 2 is even less feasible.