Bookshelf

시간 제한1초메모리 제한2048 MB

요약
선반에 고정된 책들을 하나씩 빼서 빈 공간에 다시 꽂는 조작만으로 k번째 책을 위치 p로 옮길 수 있는지 판정한다.
난이도

어려움10점 중 8점

유형
그리디, 구현
정답자
아직 제출이 없습니다

문제

A bookshelf of length LL holds nn books, B_1,⋯ ,B_nB\_1, \cdots , B\_n, arranged from left to right. Each book B_iB\_i has a width (thickness) of w_iw\_i. The heights of the bookshelf 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 B_iB\_i is placed at position xx, it occupies the interval \[x,x+w_i)\[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 00, 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 B_iB\_ii on the shelf and take it out, which creates a contiguous empty interval where it was.
  • Then insert B_iB\_i into any existing empty interval on the shelf whose length is at least w_iw\_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 B_kB\_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 B_kB\_k, and its target position pp, determine whether it is possible to place B_kB\_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 (1≤n≤100,0001 ≤ n ≤ 100\\,000; 1≤L≤1091 ≤ L ≤ 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 L−1L − 1 (inclusive), representing the positions of books B_1,⋯ ,B_nB\_1, \cdots , B\_n initially arranged on the shelf in ascending order. The third line contains nn positive integers, where the ii-th integer (1≤i≤n1 ≤ i ≤ n) is the width w_iw\_i of the ii-th book B_iB\_i in the initial arrangement. The next line contains two integers kk and pp (1≤k≤n1 ≤ k ≤ n; 0≤p≤L−10 ≤ p ≤ L − 1), where the kk-th book B_kB\_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.

예제4

  1. 예제 1

    입력
    3 6
    1 3 5
    1 2 1
    3 3
    
    예상 출력
    YES
    
  2. 예제 2

    입력
    3 6
    1 3 5
    1 2 1
    2 5
    
    예상 출력
    NO
    
  3. 예제 3

    입력
    3 7
    0 3 6
    2 3 1
    3 1
    
    예상 출력
    YES
    
  4. 예제 4

    입력
    3 7
    0 3 6
    2 3 1
    3 4
    
    예상 출력
    NO