This page is still under construction.

Parts of this page are still being built. What you see may change.

Maximized Subset

Time limit1sMemory limit128 MB

Summary
You choose k elements from the multiset to maximize the largest x with every integer from 1 to x as a subset sum.
Level

Medium7 of 10

Topics
Greedy, Sorting
Solved
No attempts yet

Problem

For a multiset AA (a set whose elements may repeat), define the function f(A)f(A) as follows: f(A)f(A) is the largest integer xx such that every integer from 11 to xx can be written as the sum of the elements of some sub-multiset of AA, while x+1x + 1 cannot be written as such a sum. (A sub-multiset is itself a multiset, so each element may be used only as many times as it appears in AA.)

You are given a multiset AA with nn elements. Choose kk of its elements to form a sub-multiset BB so that f(B)f(B) is as large as possible, and report that maximum value of f(B)f(B).

Input

The first line contains an integer tt (1≤t≤1001 \le t \le 100), the number of test cases. Each test case consists of two lines. The first line contains two integers nn and kk (1≤k≤n≤1051 \le k \le n \le 10^5). The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9), separated by single spaces, the elements of AA.

The sum of nn over all test cases does not exceed 10610^6.

Output

For each test case, print on its own line a single integer: the maximum possible value of f(B)f(B).

Examples4

  1. Example 1

    Input
    2
    3 2
    1 1 1
    5 3
    1 2 2 3 3
    
    Expected output
    2
    6
    
  2. Example 2

    Input
    1
    5 5
    1 1 1 1 1
    
    Expected output
    5
    
  3. Example 3

    Input
    1
    3 2
    2 3 4
    
    Expected output
    0
    
  4. Example 4

    Input
    1
    5 5
    1 2 4 8 16
    
    Expected output
    31