You are given a positive integer array \(A_1,A_2,...,A_N\) of length \(N\) and \(Q\) queries. In each query, given an positive integer \(K\) find the length of the longest subsequence with sum of elements less than \(K\)?
INPUT FORMAT
The first line contains an integer, \(t\) - denoting the number of test cases.
The first line of each test case contains two integers \(n\) and \(q\) - denoting the length of the array \(A\), and the number of queries.
The second line of each test case contains \(n\) positive integers — elements of \(A\).
Then \(q\) lines follow, each line contains a single positive integer \(k\) for corresponding query.
OUTPUT FORMAT
For each test case, print the answer for each query in a new line.
Constraints
\(1<=t<=1000\)
\(1<=n,q<=10^5\), both sum of \(n\) and sum of \(q\) across all test cases <= \(10^5\)
\(0 ≤ A_i ≤ 10^{12}\)
\(0 ≤ K ≤ 10^{18}\)
For first query K=8, maximum length is 2 with subsequence [5,2].
For second query K=2, there is no subsequence with sum < 2.
For third query K=20, maximum length is 3 with subsequence [5, 7, 2].
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor