QOJ.ac

QOJ

时间限制: 1.5 s 内存限制: 512 MB 总分: 100

#3638. Wooden planks

统计

As temperatures drop, the demand for firewood rises. A queue has formed in front of the firewood shop, and at the head of the queue is, naturally, Mr. Malnar.

Lumberjack Darko has $n$ logs of wood in his workshop. Mr. Malnar has a specific request and wants exactly $k$ meters of wood, which puts lumberjack Darko in a bind, but fortunately, he has his trusty saw with him.

The logs are stacked parallel to the shop wall, and Darko will place his saw perpendicular to them and make one powerful cut, sawing through all the logs in his path. Naturally, Mr. Malnar views the shop as a coordinate system where the logs are line segments parallel to the $y$-axis, and the lumberjack cuts all the segments along a line parallel to the $x$-axis. However, Mr. Malnar's eccentric demands do not end there; he requires all the freshly cut logs and, from those cut pieces, exclusively the shorter end. If the ends are of equal length, he will be satisfied with either one, but certainly not both.

Lumberjack Darko only finished vocational carpentry school, so he is not sure how to exactly fulfill all of Mr. Malnar's requirements, which is why he has called you for help! If there exists a line along which Darko can cut the logs such that the sum of the lengths of the shorter ends is exactly $k$, output it. If there is no help for Darko, output $-1$. If there are multiple such lines, output the one with the smallest $y$-coordinate.

Figure D.1 shows the cutting from the first example of the problem

Input

The first line contains the natural numbers $n$ ($1 \le n \le 10^5$) and $k$ ($1 \le k \le 10^9$) from the problem description.

The next $n$ lines contain the numbers $x_{1_i}, y_{1_i}, x_{2_i}, y_{2_i}$ ($1 \le x_{1_i}, y_{1_i}, x_{2_i}, y_{2_i} \le 10^9, x_{1_i} = x_{2_i}$) which denote the coordinates of the endpoints of the $i$-th log.

Output

In a single line, output the line with the smallest $y$-coordinate that satisfies the problem condition. If no solution exists, output $-1$. Your solution will be considered correct if the absolute and relative error is less than $10^{-5}$.

Examples

Input 1

5 4
1 2 1 4
2 3 2 7
3 1 3 5
3 6 3 8
4 2 4 6

Output 1

3.00000

Input 2

5 4
1 1 1 5
2 1 2 5
3 1 3 5
4 1 4 5
5 1 5 5

Output 2

1.80000

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.