#P14670. [ICPC 2025 Seoul R] Bookshelf
[ICPC 2025 Seoul R] Bookshelf
题目描述
:::align{center}
:::
A bookshelf of length holds books, , arranged from left to right. Each book has a width (thickness) of . The heights of the books and the books are the same. Position on the shelf corresponds to a point located units far from the left end. If a book is placed at position , it occupies the interval on the shelf. Then the intervals of the books on the shelf are pairwise disjoint. The left end of the shelf is at position 0, the right end is at position , and the shelf as a whole occupies the interval .
Rearranging the books currently on the shelf, you may perform the following operation any number of times:
- Choose one book on the shelf and take it out, which creates a contiguous empty interval where it was.
- Then insert into any existing empty interval on the shelf whose length is at least .
During this operation, all other books that remain on the shelf stay fixed—cannot slide, move, or be nudged in any way. This is because the books and the shelf have the same height and fit tightly together, so no book can move unless it is explicitly taken out. Also, you are not allowed to push or shift any other books to make room during the operation.
The owner has a favorite book among books on the shelf and wishes to place it at a specific position .
Given the initial positions of the books on the shelf, the favorite book , and its target position , determine whether it is possible to place at position after performing any number of the above operations—possibly zero.
输入格式
Your program is to read from standard input. The input starts with a line containing two integers and (; ), where is the number of books and is the length of shelf. The second line contains distinct integers between and (inclusive), representing the positions of books initially arranged on the shelf in ascending order. The third line contains positive integers, where the -th integer () is the width of the -th book in the initial arrangement. The next line contains two integers and (; ), where the -th book in the initial arrangement is the favorite one and its target position is .
输出格式
Your program is to write to standard output. Print exactly one line. Print "YES" if it is possible to place the favorite book at the target position, and print "NO" otherwise.
3 6
1 3 5
1 2 1
3 3
YES
3 6
1 3 5
1 2 1
2 5
NO
3 7
0 3 6
2 3 1
3 1
YES
3 7
0 3 6
2 3 1
3 4
NO