Maximized Subset
Time limit1sMemory limit128 MB
You choose k elements from the multiset to maximize the largest x with every integer from 1 to x as a subset sum.
Problem
For a multiset (a set whose elements may repeat), define the function as follows: is the largest integer such that every integer from to can be written as the sum of the elements of some sub-multiset of , while 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 .)
You are given a multiset with elements. Choose of its elements to form a sub-multiset so that is as large as possible, and report that maximum value of .
Input
The first line contains an integer (), the number of test cases. Each test case consists of two lines. The first line contains two integers and (). The second line contains integers (), separated by single spaces, the elements of .
The sum of over all test cases does not exceed .
Output
For each test case, print on its own line a single integer: the maximum possible value of .