#P29. [KBC001E] Difference

[KBC001E] Difference

Source

This problem is adapted from Long Long OJ. All rights reserved.

Problem Description

Given n,kn,k, and sequences a,ba,b, find the shortest interval [i,j][i,j] such that:

(minp=ijap)+kmaxp=ijbp(\min_{p=i}^ja_p)+k\le\max_{p=i}^jb_p

Output the length of the interval.

Output 1-1 if no interval is found.

Input Format

The first line consists of two integers n,k(1n105,1k106)n, k (1 \le n \le 10^5, 1 \le k \le 10^6).

The second line consists of nn integers a1,a2,,an (1ai106)a_1,a_2,\ldots,a_n\ (1 \le a_i \le 10^6).

The third line consists of nn integers b1,b2,,bn (1bi106)b_1,b_2,\ldots,b_n\ (1 \le b_i \le 10^6).

Output Format

An integer that represents the minimum length of interval.

Output 1-1 if no interval is found.

Samples

5 10
8 7 14 8 3
4 2 5 8 2
-1
5 14
11 22 3 15 6
21 20 17 22 136
1

Sample 2 Explanation

The interval is [3,3][3,3] or [5,5][5,5], because a3+k=3+14=17a_3+k=3+14=17 and a5+k=6+14=20<136a_5+k=6+14=20\lt136.