269 传统题

[CF2290G2] 环湖步道(困难版)(Lakeside Trail - Hard)

时间限制
4000ms
内存限制
256MiB
登顶 / 尝试
1/ 1
难度
5

[CF2290G2] 环湖步道(困难版)(Lakeside Trail - Hard)

Problem Statement

(This is the Hard Version of the problem; only the constraints on tt, nn, and ∑n\sum n are larger.)

A circular lakeside trail consists of nn segments numbered 11 through nn clockwise, with initial heights h1,…,hnh_1, \dots, h_n (segment nn is adjacent to segment 11). The steepness is max⁡1≤i≤n∣hi−hi+1∣\max_{1 \le i \le n} |h_i - h_{i+1}| (hn+1=h1h_{n+1} = h_1).

You have kk units of dirt to raise segments (never lower). Find the minimum possible steepness after spending at most kk units of dirt.

Input

The first line contains tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

Each test case starts with nn and kk (3≤n≤1063 \le n \le 10^6, 0≤k≤10180 \le k \le 10^{18}), followed by nn integers h1,h2,…,hnh_1, h_2, \dots, h_n (1≤hi≤1091 \le h_i \le 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 10610^6.

Output

For each test case, print a single integer — the minimum possible steepness.

Example

6
4 3
1 5 2 8
5 5
2 9 4 1 6
3 0
1 4 7
3 100
1 10 1
5 5
4 1 1 1 1
6 14
3 6 2 4 1 5
5
4
6
0
2
1

Note

  • Constraints: 1≤t≤1041 \le t \le 10^4, 3≤n≤1063 \le n \le 10^6, 0≤k≤10180 \le k \le 10^{18}, 1≤hi≤1091 \le h_i \le 10^9, ∑n≤106\sum n \le 10^6.
  • Fast I/O is recommended due to the large input size.
  • Source: Codeforces 2290G2 · Lakeside Trail (Hard Version)