QOJ.ac

QOJ

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

#12138. 书架瓶颈

الإحصائيات

Brianna 是个书虫。她家里有一个大书架,上面放着她所有的心爱之书。她的藏书种类繁多,从侦探小说、科幻小说到传记应有尽有。

最近,Brianna 又添置了 $n$ 本绘本。然而,这些新书目前到处乱放,在地板上堆成了高高的几堆。与此同时,书架的一块隔板上积满了灰尘,还堆放着一些不属于那里的杂物。这些随意摆放的新书让 Brianna 实在看不下去了,她最终决定把它们放到这块隔板上。为了做到这一点,她首先得腾出空间。

图 B.1:样例输入 3 的可视化。

Brianna 希望将这些书排成单行,且不将多本书叠放在一起。虽然书架足够宽,可以毫无问题地放下所有的书,但清理书架需要时间。因此,Brianna 希望最小化她需要清理的那部分书架的宽度。

每本书都可以描述为一个长方体,具有三个边长 $l, w$ 和 $h$。由于书架上方的空间受到上方隔板的限制,她只有在书的垂直边长不超过两块隔板之间的距离 $H$ 时,才能将书垂直放置。Brianna 可以将每本书在三维空间中随意旋转。题目保证书架足够深,无论书如何摆放,都不会掉下来。然而,所有的书都必须正确地立在隔板上,这意味着每本书必须以整个面接触隔板,而不仅仅是靠边接触。

Brianna 的书需要的最短书架宽度是多少?

输入格式

输入包含: 一行包含两个整数 $n$ 和 $H$ ($1 \le n \le 10^5, 1 \le H \le 10^9$),分别表示书的数量和书架的高度。 $n$ 行,每行包含三个整数 $l, w, h$ ($1 \le l, w, h \le 10^9$),表示书的尺寸。

输出格式

输出 Brianna 的书需要的最短书架宽度,如果无法将书放在书架上,则输出 “impossible”。

样例

样例输入 1

1 3
10 2 5

样例输出 1

5

样例输入 2

1 3
10 4 5

样例输出 2

impossible

样例输入 3

2 10
10 2 10
2 3 4

样例输出 3

4

样例输入 4

3 1000000000
1000000000 1000000000 1000000000
1000000000 1000000000 1000000000
1000000000 1000000000 1000000000

样例输出 4

3000000000

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.