#R1013. [KBC001E] Clone
[KBC001E] Clone
Problem Description
A and B are working on their homework. Today's homework consists of questions. For the -th question, A takes time to solve it, while B takes time. Because there are too many assignments, they decide to only complete some of them today, and the completed questions are numbered consecutively.
In order to quickly finish all the questions, A and B have even learned the art of cloning and can work on multiple questions at the same time.
They decide to go eat fruits after finishing their homework. B will only go to eat fruits after completing all the planned questions for the day. However, as long as any of A's clones completes the assigned questions, A will immediately go eat fruits.
A only needs time to finish eating all the fruits. A wants to determine the range of questions in order to finish eating all the fruits without letting B eat any. At the same time, A wants to minimize the total number of questions he has to solve. Can you help him figure out the minimum number of questions he has to solve?
Simplified Statement
Given , and sequences , find the shortest interval such that $\displaystyle(\min_{p=i}^ja_p)+k\leq\max_{p=i}^jb_p$. Output the length of the interval, and if no interval is found, output .
Constraints
Input
The input is given from Standard Input in the following format:
$n\ \ k\\a_1\ \ a_2\ \ \cdots\ \ a_n\\b_1\ \ b_2\ \ \cdots\ \ b_n$
Output
An integer that represents the minimum number of questions A has to solve. If there is no solution, output .
Sample Input 1
5 10
8 7 14 8 3
4 2 5 8 2
Sample Output 1
-1
Sample Input 2
5 14
11 22 3 15 6
21 20 17 22 136
Sample Output 2
1
The interval is or , because and 。