#P7731. 『PG1』[JDWOI-2] 猪猪大厦
『PG1』[JDWOI-2] 猪猪大厦
Description
built an extremely huge building, which can be seen as a plane. On this plane there are infinitely long escalators that are neither perpendicular nor parallel to the ground. They can be seen as linear functions, and all of them go to the right, i.e. in the positive direction of the axis.
At the intersection point of two escalators, you can transfer by paying .
Someone wants to text to ask to come to find him.
However:

So he can only walk over to find .
He is currently at the point with -coordinate on the -th escalator.
is at the point with -coordinate on the -th escalator.
What is the minimum cost in for him to get there?
Input Format
The first line contains a positive integer .
The second line contains four integers .
The next lines: the -th line contains two numbers , meaning the escalator is given by .
Output Format
Output the minimum cost in . If it is impossible to reach, output -1.
1
1 1 1 2
50 -30
0
2
1 2 2 2
1 0
2 0
-1
2
1 -1 2 1
1 0
2 0
1
Hint
This problem uses subtasks.
: .
: .
: , .
Escalators are numbered starting from .
Translated by ChatGPT 5
京公网安备 11011102002149号