#P12327. Snail's Bamboo Journey
Snail's Bamboo Journey
Snail's Bamboo Journey
A snail starts at the origin \((0,0)\) on the \(x\)-axis. There are \(n\) bamboo poles growing on the \(x\)-axis, each located at \(x_1, x_2, \ldots, x_n\). Every bamboo pole is vertical (parallel to the \(y\)-axis), its base is at \(y=0\), and its height is effectively infinite (its width is negligible).
The snail wishes to travel from the origin to the base of the \(n\)th bamboo pole (i.e. \((x_n,0)\)). It may only move in two ways:
- Walking on the ground (the \(x\)-axis) at a speed of \(1\) unit per second.
- Climbing on a bamboo pole. When climbing upward, the snail moves at \(0.7\) units per second; when descending, it moves at \(1.3\) units per second.
To help shorten its journey, magical portals have been set up between every two consecutive bamboo poles (i.e. between the \(i\)th and \(i+1\)th pole for \(1 \le i < n\)). Specifically, for \(1 \le i < n\), if the snail is at exactly height \(a_i\) on the \(i\)th pole (i.e. at \((x_i,a_i)\)), it can instantly teleport to the \((i+1)\)th pole at height \(b_{i+1}\) (i.e. arriving at \((x_{i+1},b_{i+1})\)).
The snail can choose to either walk on the ground between bamboo poles or use a portal. Note that if it uses a portal, it may have to climb up or down on the bamboo to reach the required height for departure or to return to the ground. When departing from a bamboo pole to use a portal, the snail must be exactly at height \(a_i\). Similarly, after teleportation, if it wishes to walk on the ground (or later use a portal on that bamboo), it must adjust its height to \(0\) (or to \(a_{i+1}\)) by climbing up or down as needed.
Your task is to compute the minimum time (in seconds) needed for the snail to reach its destination at \((x_n,0)\).
Note on vertical movement:
- Climbing upward from \(y_1\) to \(y_2\) (with \(y_2 \ge y_1\)) takes \(\displaystyle \frac{y_2 - y_1}{0.7}\) seconds.
- Descending from \(y_1\) to \(y_2\) (with \(y_1 \ge y_2\)) takes \(\displaystyle \frac{y_1 - y_2}{1.3}\) seconds.
Input/Output via portals: When using a portal from the \(i\)th bamboo to the \((i+1)\)th bamboo:
- The snail must first climb (if needed) from its current position (typically the ground at \(y=0\)) to \(a_i\) at the \(i\)th bamboo.
- After teleportation, it appears at \((x_{i+1}, b_{i+1})\) on the \((i+1)\)th bamboo. It can then either descend to \(0\) to get onto the ground or climb to \(a_{i+1}\) if it plans to use the next portal.
inputFormat
The input consists of four lines:
- An integer \(n\) (\(n \ge 2\)), the number of bamboo poles.
- \(n\) space-separated real numbers: \(x_1, x_2, \ldots, x_n\) (in increasing order), the positions of the bamboo poles on the \(x\)-axis.
- \(n-1\) space-separated real numbers: \(a_1, a_2, \ldots, a_{n-1}\). For \(1 \le i < n\), \(a_i\) is the required departure height on the \(i\)th bamboo if using a portal.
- \(n-1\) space-separated real numbers: \(b_2, b_3, \ldots, b_n\). For \(2 \le j \le n\), \(b_j\) is the arrival height on the \(j\)th bamboo when teleporting from the previous pole.
outputFormat
Output a single real number---the minimum number of seconds required for the snail to reach \((x_n,0)\). Answers within a reasonable error tolerance will be accepted.
sample
2
1 3
2
1
3.000000