CF1630B.Range and Partition
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Given an array a of n integers, find a range of values [x,y] ( x≤y ), and split a into exactly k ( 1≤k≤n ) subarrays in such a way that:
- Each subarray is formed by several continuous elements of a , that is, it is equal to al,al+1,…,ar for some l and r ( 1≤l≤r≤n ).
- Each element from a belongs to exactly one subarray.
- In each subarray the number of elements inside the range [x,y] (inclusive) is strictly greater than the number of elements outside the range. An element with index i is inside the range [x,y] if and only if x≤ai≤y .
Print any solution that minimizes y−x .
输入格式
The input consists of multiple test cases. The first line contains a single integer t ( 1≤t≤3⋅104 ) — the number of test cases. Description of the test cases follows.
The first line of each test case contains two integers n and k ( 1≤k≤n≤2⋅105 ) — the length of the array a and the number of subarrays required in the partition.
The second line of each test case contains n integers a1,a2,…,an ( 1≤ai≤n ) where ai is the i -th element of the array.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105 .
输出格式
For each test case, print k+1 lines.
In the first line, print x and y — the limits of the found range.
Then print k lines, the i -th should contain li and ri ( 1≤li≤ri≤n ) — the limits of the i -th subarray.
You can print the subarrays in any order.
输入输出样例
输入#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
输出#1
1 2 1 2 2 2 1 3 4 4 5 5 1 1 2 2 3 11
说明/提示
In the first test, there should be only one subarray, which must be equal to the whole array. There are 2 elements inside the range [1,2] and 0 elements outside, if the chosen range is [1,1] , there will be 1 element inside ( a1 ) and 1 element outside ( a2 ), and the answer will be invalid.
In the second test, it is possible to choose the range [2,2] , and split the array in subarrays (1,3) and (4,4) , in subarray (1,3) there are 2 elements inside the range ( a2 and a3 ) and 1 element outside ( a1 ), in subarray (4,4) there is only 1 element ( a4 ), and it is inside the range.
In the third test, it is possible to choose the range [5,5] , and split the array in subarrays (1,4) , (5,7) and (8,11) , in the subarray (1,4) there are 3 elements inside the range and 1 element outside, in the subarray (5,7) there are 2 elements inside and 1 element outside and in the subarray (8,11) there are 3 elements inside and 1 element outside.