Gaurav And Sub-array
83% Success8055 Attempts20 Points1s Time Limit256MB Memory1024 KB Max Code

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:

\(1 \le N \le 100000\)
\(1 \le Q \le 5\)
\(0 \le K \le 10^9\)
\(0 \le A[i] \le 10^9\)

Examples
Input
4 3
1 2 4 8
1
2
3
Output
1
2
3
Explanation

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

Loading Editor...
Results