Under construction

Still being built. Things may change

There Are n Chairs

Interview

Time limit1sMemory limit1024 MB

Summary
Pick chairs whose total width reaches H so that the largest height gap between neighbors in the row is as small as possible.
Level

Medium5 of 10

Topics
Sorting, Binary search, Greedy
Solved
No attempts yet

Problem

Vlad has finally become team lead, but he has no time to get home and will have to sleep at the office. Not every IT company can afford a roomy coworking space with a place to nap, so Vlad will sleep on office chairs.

The office has nn chairs. The ii-th chair has height hih_i and width wiw_i. Vlad picks any set of chairs [i1,i2,…,ik][i_1, i_2, \ldots, i_k] and lines them up in a row to lie on. Vlad's height is HH, so for him to lie down comfortably, the total width of the chosen chairs must be at least HH:

∑j=1kwij≥H\sum\limits_{j=1}^k w_{i_j} \ge H

Sleeping on chairs of different heights is uncomfortable. The discomfort of a row is the largest height difference between two adjacent chairs in it:

max⁡j=2k∣hij−hij−1∣\max\limits_{j=2}^k |h_{i_j} - h_{i_{j-1}}|

A row with one chair has discomfort 00. Help Vlad choose chairs so that he can lie down and the discomfort is as small as possible.

Input

The first line contains two integers nn and HH, the number of chairs and Vlad's height (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5; 1≤H≤1091 \le H \le 10^9). The second line contains nn integers hih_i, the chair heights (1≤hi≤1091 \le h_i \le 10^9). The third line contains nn integers wiw_i, the chair widths (1≤wi≤1091 \le w_i \le 10^9). It is guaranteed that HH does not exceed the sum of all wiw_i.

Output

Print one integer: the minimum possible discomfort among all valid sets.

Hints

In the first sample, place chairs 2 and 4 in either order. In the second sample, the sets [1, 5] and [2, 4, 3] both work. Order matters: the row [2, 3, 4] has discomfort max⁡(∣5−3∣,∣4−5∣)=max⁡(2,1)=2\max(|5 - 3|, |4 - 5|) = \max(2, 1) = 2, which is more than the row [2, 4, 3] gives.

Examples2

  1. Example 1

    Input
    4 7
    1 4 1 2
    1 4 2 3
    
    Expected output
    2
    
  2. Example 2

    Input
    5 6
    1 3 5 4 2
    5 4 3 2 1
    
    Expected output
    1