QOJ.ac

QOJ

حد الوقت: 1.5 s حد الذاكرة: 512 MB مجموع النقاط: 100

#3638. 木板

الإحصائيات

随着气温下降,对木柴的需求也在增加。木材店前排起了长队,排在队首的自然是我们的 Malnar 先生。

伐木工 Darko 的作坊里有 $n$ 根原木。Malnar 先生有一个特殊的要求,他需要正好 $k$ 米长的木材,这给伐木工 Darko 带来了麻烦,但幸运的是,他随身带着他那把忠实的锯子。

原木平行于木材店的墙壁堆放,Darko 会将锯子垂直于它们放置,并用力锯下,切断路径上的所有原木。当然,Malnar 先生将木材店视为一个坐标系,其中原木是平行于 $y$ 轴的线段,而伐木工在某条平行于 $x$ 轴的直线上切断所有线段。Malnar 先生的古怪要求还没结束,他要求得到所有刚锯下的木材,并且只取这些木材中较短的那一端。如果两端的长度相等,取哪一端都可以,但当然不能两端都取。

伐木工 Darko 只读过木工职业学校,所以他不确定如何准确满足 Malnar 先生的所有要求,因此他向你寻求帮助!如果存在一条直线,使得 Darko 可以切断原木,且所有较短木材的长度之和正好为 $k$,请输出这条直线的 $y$ 坐标;如果不存在这样的直线,请输出 $-1$。如果存在多条满足条件的直线,请输出 $y$ 坐标最小的那一条。

图 D.1 展示了第一个样例中的切割过程

输入格式

第一行包含自然数 $n$ ($1 \le n \le 10^5$) 和 $k$ ($1 \le k \le 10^9$)。

接下来的 $n$ 行包含数字 $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}$),表示第 $i$ 根原木端点的坐标。

输出格式

在唯一的一行中输出满足题目条件的 $y$ 坐标最小的直线。如果不存在解,输出 $-1$。如果你的答案与标准答案的绝对误差或相对误差小于 $10^{-5}$,则视为正确。

样例

输入格式 1

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

输出格式 1

3.00000

输入格式 2

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

输出格式 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.