Sky Walking
시간 제한4초메모리 제한1024 MB
건물은 수직 선분, 하늘길은 수평 선분일 때 두 건물 바닥 사이의 최단 경로 길이를 구한다.
문제
Kenan drew a plan of the buildings and skywalks along one side of the main avenue of Baku. There are buildings numbered from to and skywalks numbered from to . The plan is drawn on a two-dimensional plane, where the buildings and skywalks are vertical and horizontal segments respectively.
The bottom of building is located at point and the building has height . Hence, it is a segment connecting the points and .
Skywalk has endpoints at buildings numbered and and has a positive -coordinate . Hence, it is a segment connecting the points and .
A skywalk and a building intersect if they share a common point. Hence, a skywalk intersects two buildings at its two endpoints, and may also intersect other buildings in between.
Kenan would like to find the length of the shortest path from the bottom of building to the bottom of building , assuming that one can only walk along the buildings and skywalks, or determine that no such path exists. Note that it is not allowed to walk on the ground, i.e. along the horizontal line with -coordinate .
One can walk from a skywalk into a building or vice versa at any intersection. If the endpoints of two skywalks are at the same point, one can walk from one skywalk to the other.
Your task is to help Kenan answer his question.
제한
- (for all )
- (for all )
- (for all )
- No two skywalks have a common point, except maybe on their endpoints.
예제
이 문제는 공개된 예제가 없습니다.