题库练习 Black Cells
← 上一题 下一题 →

A15938 | Black Cells

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

You are playing with a really long strip consisting of $10^{18}$ white cells, numbered from left to right as $0$ , $1$ , $2$ and so on. You are controlling a special pointer that is initially in cell $0$ . Also, you have a "Shift" button you can press and hold.

In one move, you can do one of three actions:

- move the pointer to the right (from cell $x$ to cell $x + 1$ );
- press and hold the "Shift" button;
- release the "Shift" button: the moment you release "Shift", all cells that were visited while "Shift" was pressed are colored in black.

(Of course, you can't press Shift if you already hold it. Similarly, you can't release Shift if you haven't pressed it.)Your goal is to color at least $k$ cells, but there is a restriction: you are given $n$ segments $[l_i, r_i]$ — you can color cells only inside these segments, i. e. you can color the cell $x$ if and only if $l_i \le x \le r_i$ for some $i$ .

What is the minimum number of moves you need to make in order to color at least $k$ cells black?

输入格式

The first line contains a single integer $t$ ( $1 \le t \le 10^4$ ) — the number of test cases.

The first line of each test case contains two integers $n$ and $k$ ( $1 \le n \le 2 \cdot 10^5$ ; $1 \le k \le 10^9$ ) — the number of segments and the desired number of black cells, respectively.

The second line contains $n$ integers $l_1, l_2, \dots, l_n$ ( $1 \le l_1 < l_2 < \dots < l_n \le 10^9$ ), where $l_i$ is the left border of the $i$ -th segment.

The third line contains $n$ integers $r_1, r_2, \dots, r_n$ ( $1 \le r_i \le 10^9$ ; $l_i \le r_i < l_{i + 1} - 1$ ), where $r_i$ is the right border of the $i$ -th segment.

Additional constraints on the input:

- every cell belongs to at most one segment;
- the sum of $n$ doesn't exceed $2 \cdot 10^5$ .

输出格式

For each test case, print the minimum number of moves to color at least $k$ cells black, or $-1$ if it's impossible.

输入输出样例

输入 #1
4
2 3
1 3
1 4
4 20
10 13 16 19
11 14 17 20
2 3
1 3
1 10
2 4
99 999999999
100 1000000000
输出 #1
8
-1
7
1000000004
C++ 编辑器
输入
输出