#P14670. [ICPC 2025 Seoul R] Bookshelf

[ICPC 2025 Seoul R] Bookshelf

题目描述

:::align{center} :::

A bookshelf of length LL holds nn books, B1,,BnB_1, \cdots, B_n, arranged from left to right. Each book BiB_i has a width (thickness) of wiw_i. The heights of the books and the books are the same. Position xx on the shelf corresponds to a point located xx units far from the left end. If a book BiB_i is placed at position xx, it occupies the interval [x,x+wi)[x, x + w_i) 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 LL, and the shelf as a whole occupies the interval [0,L)[0, L).

Rearranging the books currently on the shelf, you may perform the following operation any number of times:

  • Choose one book BiB_i on the shelf and take it out, which creates a contiguous empty interval where it was.
  • Then insert BiB_i into any existing empty interval on the shelf whose length is at least wiw_i.

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 BkB_k among nn books on the shelf and wishes to place it at a specific position pp.

Given the initial positions of the books on the shelf, the favorite book BkB_k, and its target position pp, determine whether it is possible to place BkB_k at position pp 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 nn and LL (1n100,0001 \le n \le 100,000; 1L1091 \le L \le 10^9), where nn is the number of books and LL is the length of shelf. The second line contains nn distinct integers between 00 and L1L-1 (inclusive), representing the positions of books B1,,BnB_1, \cdots, B_n initially arranged on the shelf in ascending order. The third line contains nn positive integers, where the ii-th integer (1in1 \le i \le n) is the width wiw_i of the ii-th book BiB_i in the initial arrangement. The next line contains two integers kk and pp (1kn1 \le k \le n; 0pL10 \le p \le L-1), where the kk-th book BkB_k in the initial arrangement is the favorite one and its target position is pp.

输出格式

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