You are given an array \(A[]\) consisting of \(N\) non-negative integers. Now, you need to answer \(Q\) queries of the following type given an integer K in each query.
You need to find the minimum length L of any subarray of A, such that if all elements of this subarray are represented in binary notation and concatenated to form a binary string, then no of 1's in the resulting string is at least K.
Input Format:
The first line of the input consists of two space-separated integers N and Q.
The second line contains N space separated integers, where the \(i^{th}\)integer denotes \(A[i]\)
Next Q lines contains a non-negative integer K.
Output Format:
For each query out of the Q ones, print the answer on a new line. If for a paritcular query no valid subarray exists, then print -1 instead as the answer to that query.
Constraints:
4 3 1 2 4 8 1 2 3
1 2 3
For first query consider subarray A[1,1], then binary string representing A[1,1] is 01 which has one 1's.
For second query consider subarray A[1,2], then binary string is 0110 which has two 1's.
Similarly, for third query consider subarray A[1,3].
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