This page is still under construction.

Parts of this page are still being built. What you see may change.

Walking Is Annoying

Interview

Time limit1sMemory limit1024 MB

Summary
Given N rickshaws at sorted positions, each covering a range to its right, find the minimum number of transfers to reach point M without walking.
Level

Medium6 of 10

Topics
Greedy, BFS, Array, Two pointers
Solved
No attempts yet

Problem

On a line there are NN points pip_i, each with a rickshaw puller who can carry a passenger up to xix_i units. That is, the puller at pip_i takes the passenger to one of pip_i, pi+1p_i+1, pi+2p_i+2, ......, pi+xip_i+x_i.

Hyeonsol, the laziest person in the world when it comes to walking, wants to reach the destination MM without walking, riding rickshaws only. Hyeonsol is already on the first rickshaw. Find the minimum number of rickshaw transfers needed to reach the destination.

Input

The first line gives NN and MM, separated by a space. (1≤N≤100 0001 \le N \le 100\,000, 1≤M≤1 000 0001 \le M \le 1\,000\,000)

The second line gives the positions p1p_1, p2p_2, ...... , pNp_N of the points, separated by spaces in increasing order. (1≤p1<p2<...<pN≤1 000 0001 \le p_1 \lt p_2 \lt ... \lt p_N \le 1\,000\,000, p1≤Mp_1 \le M)

The third line gives the maximum travel distances x1x_1, x2x_2, ...... , xNx_N of the rickshaw pullers, separated by spaces in that order. (1≤xi≤10 0001 \le x_i \le 10\,000)

Output

Print the minimum number of rickshaw transfers Hyeonsol needs to reach the destination without walking. If the destination cannot be reached, print -1.

Examples2

  1. Example 1

    Input
    3 9
    1 3 5
    5 5 4
    
    Expected output
    1
    
  2. Example 2

    Input
    3 11
    1 3 5
    5 5 4
    
    Expected output
    -1