Problem B
Driving Lanes
While driving around a curve on the highway, Sam realizes that if they use the inside lane, they travel a shorter distance. Sam wonders what is the minimum distance needed to travel to the destination.
The multilane highway consists of a sequence of
straightaways that are connected by curves. When going around a
curve, the distance travelled depends on which lane you are in.
Each curve has a curvature
Whenever Sam is on a straightaway, they may change from one
lane into an adjacent lane. When changing to an adjacent lane,
Sam moves forward
![\includegraphics[width=0.8\textwidth ]{chla.pdf}](/problems/drivinglanes/file/statement/en/img-0001.png)
Sam starts in lane
Input
The first line of input contains two integers
The second line of input contains two integers
The next
The next
The
Output
Display the minimum distance Sam must travel.
Sample Input 1 | Sample Output 1 |
---|---|
4 3 5 2 10 10 10 10 4 -1 4 -1 4 1 |
51 |
Sample Input 2 | Sample Output 2 |
---|---|
4 3 5 2 10 10 10 10 10 -3 10 -3 10 1 |
61 |