CF BUDDY
← Problems·

1852A · Ntarsis' Set

1800 · binary search, math, number theory

Problem: Ntarsis has been given a set SS, initially containing integers 1,2,3,,1010001, 2, 3, \ldots, 10^{1000} in sorted order. Every day, he will remove the a1a_1-th, a2a_2-th, \ldots, ana_n-th smallest numbers in SS simultaneously.

What is the smallest element in SS after kk days?

Input Format: Each test contains multiple test cases. The first line contains the number of test cases tt (1t1051 \le t \le 10^5). The description of the test cases follows.

The first line of each test case consists of two integers nn and kk (1n,k21051 \leq n,k \leq 2 \cdot 10^5) — the length of aa and the number of days.

The following line of each test case consists of nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \leq a_i \leq 10^9) — the elements of array aa.

It is guaranteed that:

  • The sum of nn over all test cases won't exceed 21052 \cdot 10^5;
  • The sum of kk over all test cases won't exceed 21052 \cdot 10^5;
  • a1<a2<<ana_1 < a_2 < \cdots < a_n for all test cases.

Output Format: For each test case, print an integer that is the smallest element in SS after kk days.

Note: For the first test case, each day the 11-st, 22-nd, 44-th, 55-th, and 66-th smallest elements need to be removed from SS. So after the first day, SS will become \requirecancel\require{cancel} {1,2,3,4,5,6,7,8,9,}={3,7,8,9,}\{\cancel 1, \cancel 2, 3, \cancel 4, \cancel 5, \cancel 6, 7, 8, 9, \ldots\} = \{3, 7, 8, 9, \ldots\}. The smallest element is 33.

For the second case, each day the 11-st, 33-rd, 55-th, 66-th and 77-th smallest elements need to be removed from SS. SS will be changed as follows:

DaySS beforeSS after1\{\cancel 1, 2, \cancel 3, 4, \cancel 5, \cancel 6, \cancel 7, 8, 9, 10, \ldots \}$$$$$$\to$$$$$$\{2, 4, 8, 9, 10, \ldots\}2\{\cancel 2, 4, \cancel 8, 9, \cancel{10}, \cancel{11}, \cancel{12}, 13, 14, 15, \ldots\}$$$$$$\to$$$$$$\{4, 9, 13, 14, 15, \ldots\}3\{\cancel 4, 9, \cancel{13}, 14, \cancel{15}, \cancel{16}, \cancel{17}, 18, 19, 20, \ldots\}$$$$$$\to$$$$$$\{9, 14, 18, 19, 20, \ldots\}

The smallest element left after k=3k = 3 days is 99.

Sample Cases

Case 1

Input

7
5 1
1 2 4 5 6
5 3
1 3 5 6 7
4 1000
2 3 4 5
9 1434
1 4 7 9 12 15 17 18 20
10 4
1 3 5 7 9 11 13 15 17 19
10 6
1 4 7 10 13 16 19 22 25 28
10 150000
1 3 4 5 10 11 12 13 14 15

Output

3
9
1
12874
16
18
1499986

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback