#P12859. [NERC 2020 Online] Jumping Cat

    ID: 12636 Type: RemoteJudge 2000ms 512MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>2020Special JudgeICPCNERC/NEERC

[NERC 2020 Online] Jumping Cat

题目描述

A city skyline is specified by nn integers d1,d2,,dnd_1, d_2, \ldots, d_n (0<d1<d2<<dn0 < d_1 < d_2 < \ldots < d_n) and nn integers h1,h2,,hnh_1, h_2, \ldots, h_n.

A skyline surface consists of nn horizontal line segments, the ii-th segment connects points (di1,hi)(d_{i-1}, h_i) and (di,hi)(d_i, h_i), where d0=0d_0 = 0. 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, (0,h1)(0, h_1), to the rightmost point of the skyline, (dn,hn)(d_n, h_n). To achieve that, the cat performs a sequence of moves. Each move is one of two types:

  • Walk\emph{Walk} from point (x1,y1)(x_1, y_1) to point (x2,y2)(x_2, y_2). Both points must belong to the same surface segment, i.e. there exists ii such that y1=y2=hiy_1 = y_2 = h_i and di1x1,x2did_{i-1} \le x_1, x_2 \le d_i. A trajectory of a walk is a straight line segment.
  • Jump\emph{Jump} from point (x1,y1)(x_1, y_1) to point (x2,y2)(x_2, y_2). Points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) 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 (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) is at most LL;
    • the line segment between (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) does not intersect any of the buildings, i.e. thereis no point (x,y)(x, y) belonging to the segment and integer ii such that di1<x<did_{i-1} < x < d_i and y<hiy < h_i.

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 (0,h1)(0, h_1) to (dn,hn)(d_n, h_n), or determine that the goal is unreachable.

输入格式

The first line contains two integers nn and LL (1n501 \le n \le 50; 1L1001 \le L \le 100).

The second line contains nn integers d1,d2,,dnd_1, d_2, \ldots, d_n (0<d1<d2<<dn10000 < d_1 < d_2 < \ldots < d_n \le 1000).

The third line contains nn integers h1,h2,,hnh_1, h_2, \ldots, h_n (1hi1001 \le h_i \le 100; hihi+1h_i \ne h_{i+1}).

输出格式

Output a single floating-point number --- the length of the shortest trajectory from point (0,h1)(0, h_1) to point (dn,hn)(d_n, h_n), or 1-1 if no valid trajectory exists.

Your answer will be considered correct if its absolute or relative error doesn't exceed 10910^{-9}.

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.