#P16410. [Algo Beat Contest 004 F] Fortune of Golden Cheese
[Algo Beat Contest 004 F] Fortune of Golden Cheese
Problem Description
The mouse found a piece of golden cheese in a grassland, but unfortunately set up electric wires around it.
The clever hired an electrician. However, the electrician is very dishonest and charges some money each time he helps cut off the power of one wire.
For the golden cheese, has to spend all his savings.
The grassland is a square, with the bottom-left corner as the origin.
The mouse already knows the coordinates of the golden cheese and also knows the layout of the wires.
Both ends of each wire are tied to poles on the boundary of the grassland, with endpoints at and . In particular, no wire is collinear with the boundary of the grassland, and the mouse will not get electrocuted when standing at an endpoint of a wire.
The electrician charges dollars for disabling one wire, and has only dollars in total.
Although is clever, he is not as experienced as the electrician at cheating money. He might focus only on getting the golden cheese and end up owing a lot of debt. So please help him: if the required payment exceeds the mouse’s savings, make him give up the cheese and output -1. Otherwise, compute the maximum amount of money he can have left while reaching the cheese without getting electrocuted, to decide today’s dinner.
Input Format
The first line contains three integers , representing the number of wires, the money the electrician charges, and ’s savings.
The next lines each contain integers , representing the coordinates of the two endpoints of the -th wire.
The next line contains two floating-point numbers , representing the coordinates of the treasure.
Output Format
Output one line: the maximum amount of money can have left. If it is not enough, output -1.
11 5 200
0 750000 250000 1000000
0 650000 450000 1000000
0 500000 500000 1000000
250000 0 750000 1000000
500000 0 1000000 500000
0 250000 1000000 500000
450000 1000000 1000000 500000
250000 1000000 750000 0
0 750000 500000 0
0 650000 300000 0
0 200000 500000 0
300200.0 500000.0
190
Hint
Sample Explanation
The grassland looks like this:

The orange point is the golden cheese, and the black lines are the wires. If wants to get the cheese, he needs the electrician to disable one of the two wires marked in purple on the left or on the right.
This costs dollars. The mouse originally had dollars, and now has dollars left. He can get the golden cheese and still enjoy a hearty dinner.
Constraints
- .
- .
- , .
Translated by ChatGPT 5