QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 1024 MB Total points: 100

#15464. Bookshelf

统计

一个长度为 $L$ 的书架上放置了 $n$ 本书 $B_1, \dots, B_n$,从左到右排列。每本书 $B_i$ 的宽度(厚度)为 $w_i$。书架和书的高度相同。书架上的位置 $x$ 对应距离左端 $x$ 个单位的点。如果书 $B_i$ 放置在位置 $x$,它将占据书架上的区间 $[x, x + w_i)$。此时,书架上各本书占据的区间两两不相交。书架左端位于位置 $0$,右端位于位置 $L$,整个书架占据区间 $[0, L)$。

在重新排列书架上的书时,你可以执行任意次数以下操作:

  • 选择书架上的一本书 $B_i$ 并将其取出,这会在它原来的位置产生一个连续的空区间。
  • 然后将 $B_i$ 插入到书架上任何长度至少为 $w_i$ 的现有空区间中。

在此操作过程中,留在书架上的所有其他书保持固定——不能滑动、移动或以任何方式被挪动。这是因为书和书架高度相同且紧密贴合,所以除非明确取出,否则任何书都无法移动。此外,在操作过程中,不允许推动或移动其他任何书来腾出空间。

书的主人有 $n$ 本书中最喜欢的一本 $B_k$,并希望将其放置在特定位置 $p$。

给定书架上书的初始位置、最喜欢的书 $B_k$ 以及目标位置 $p$,请确定在执行任意次数(可能为零次)上述操作后,是否可以将 $B_k$ 放置在位置 $p$。

输入格式

程序从标准输入读取数据。输入的第一行包含两个整数 $n$ 和 $L$ ($1 \le n \le 100,000$; $1 \le L \le 10^9$),其中 $n$ 是书的数量,$L$ 是书架的长度。第二行包含 $n$ 个介于 $0$ 和 $L - 1$(含)之间的不同整数,表示初始排列中书 $B_1, \dots, B_n$ 的位置,按升序排列。第三行包含 $n$ 个正整数,其中第 $i$ 个整数 ($1 \le w_i \le L$) 是初始排列中第 $i$ 本书 $B_i$ 的宽度 $w_i$。下一行包含两个整数 $k$ 和 $p$ ($1 \le k \le n$; $0 \le p \le L - 1$),其中初始排列中的第 $k$ 本书 $B_k$ 是最喜欢的那一本,其目标位置为 $p$。

输出格式

程序向标准输出写入数据。仅打印一行。如果可以将最喜欢的书放置在目标位置,则打印 “YES”,否则打印 “NO”。

样例

输入 1

3 6
1 3 5
1 2 1
3 3

输出 1

YES

输入 2

3 6
1 3 5
1 2 1
2 5

输出 2

NO

输入 3

3 7
0 3 6
2 3 1
3 1

输出 3

YES

输入 4

3 7
0 3 6
2 3 1
3 4

输出 4

NO

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.