#P12859. [NERC 2020 Online] Jumping Cat
[NERC 2020 Online] Jumping Cat
题目描述
A city skyline is specified by integers () and integers .
A skyline surface consists of horizontal line segments, the -th segment connects points and , where . Each segment is a roof of a building.
A cat (which is so small that can be considered a point) wants to get from the leftmost point of the skyline, , to the rightmost point of the skyline, . To achieve that, the cat performs a sequence of moves. Each move is one of two types:
- from point to point . Both points must belong to the same surface segment, i.e. there exists such that and . A trajectory of a walk is a straight line segment.
- from point to point . Points and must belong to different surface segments. A trajectory of a jump is a straight line segment and must satisfy the following constraints:
- the distance between and is at most ;
- the line segment between and does not intersect any of the buildings, i.e. thereis no point belonging to the segment and integer such that and .
The length of the cat's trajectory is the sum of lengths of all the moves in it. Find the shortest trajectory for the cat to get from to , or determine that the goal is unreachable.
输入格式
The first line contains two integers and (; ).
The second line contains integers ().
The third line contains integers (; ).
输出格式
Output a single floating-point number --- the length of the shortest trajectory from point to point , or if no valid trajectory exists.
Your answer will be considered correct if its absolute or relative error doesn't exceed .
6 5
3 9 11 12 16 18
5 1 6 2 5 7
25.83095189484530047
6 4
3 9 11 12 16 18
5 1 6 2 5 7
-1
提示
The picture for the first sample is shown below.