#P1630B. Range and Partition

    ID: 84 Type: RemoteJudge 2000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>binary searchconstructive algorithmsdata structuresgreedytwo pointers*1800

Range and Partition

No submission language available for this problem.

Description

Given an array aa of nn integers, find a range of values [x,y][x, y] (xyx \le y), and split aa into exactly kk (1kn1 \le k \le n) subarrays in such a way that:

  • Each subarray is formed by several continuous elements of aa, that is, it is equal to al,al+1,,ara_l, a_{l+1}, \ldots, a_r for some ll and rr (1lrn1 \leq l \leq r \leq n).
  • Each element from aa belongs to exactly one subarray.
  • In each subarray the number of elements inside the range [x,y][x, y] (inclusive) is strictly greater than the number of elements outside the range. An element with index ii is inside the range [x,y][x, y] if and only if xaiyx \le a_i \le y.

Print any solution that minimizes yxy - x.

The input consists of multiple test cases. The first line contains a single integer tt (1t31041 \leq t \leq 3 \cdot 10^4) — the number of test cases. Description of the test cases follows.

The first line of each test case contains two integers nn and kk (1kn21051 \le k \le n \le 2 \cdot 10^5) — the length of the array aa and the number of subarrays required in the partition.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ain1 \le a_i \le n) where aia_i is the ii-th element of the array.

It is guaranteed that the sum of nn over all test cases does not exceed 21052\cdot10^5.

For each test case, print k+1k+1 lines.

In the first line, print xx and yy — the limits of the found range.

Then print kk lines, the ii-th should contain lil_i and rir_i (1lirin1\leq l_i \leq r_i \leq n) — the limits of the ii-th subarray.

You can print the subarrays in any order.

Input

The input consists of multiple test cases. The first line contains a single integer tt (1t31041 \leq t \leq 3 \cdot 10^4) — the number of test cases. Description of the test cases follows.

The first line of each test case contains two integers nn and kk (1kn21051 \le k \le n \le 2 \cdot 10^5) — the length of the array aa and the number of subarrays required in the partition.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ain1 \le a_i \le n) where aia_i is the ii-th element of the array.

It is guaranteed that the sum of nn over all test cases does not exceed 21052\cdot10^5.

Output

For each test case, print k+1k+1 lines.

In the first line, print xx and yy — the limits of the found range.

Then print kk lines, the ii-th should contain lil_i and rir_i (1lirin1\leq l_i \leq r_i \leq n) — the limits of the ii-th subarray.

You can print the subarrays in any order.

Samples

Sample Input 1

3
2 1
1 2
4 2
1 2 2 2
11 3
5 5 5 1 5 5 1 5 5 5 1

Sample Output 1

1 2
1 2
2 2
1 3
4 4
5 5
1 1
2 2
3 11

Note

In the first test, there should be only one subarray, which must be equal to the whole array. There are 22 elements inside the range [1,2][1, 2] and 00 elements outside, if the chosen range is [1,1][1, 1], there will be 11 element inside (a1a_1) and 11 element outside (a2a_2), and the answer will be invalid.

In the second test, it is possible to choose the range [2,2][2, 2], and split the array in subarrays (1,3)(1, 3) and (4,4)(4, 4), in subarray (1,3)(1, 3) there are 22 elements inside the range (a2a_2 and a3a_3) and 11 element outside (a1a_1), in subarray (4,4)(4, 4) there is only 11 element (a4a_4), and it is inside the range.

In the third test, it is possible to choose the range [5,5][5, 5], and split the array in subarrays (1,4)(1, 4), (5,7)(5, 7) and (8,11)(8, 11), in the subarray (1,4)(1, 4) there are 33 elements inside the range and 11 element outside, in the subarray (5,7)(5, 7) there are 22 elements inside and 11 element outside and in the subarray (8,11)(8, 11) there are 33 elements inside and 11 element outside.