CF BUDDY
← Problems·

1903D1 · Maximum And Queries (easy version)

1700 · binary search, bitmasks, brute force

Problem: This is the easy version of the problem. The only difference between the two versions is the constraint on nn and qq, the memory and time limits. You can make hacks only if all versions of the problem are solved.

Theofanis really likes to play with the bits of numbers. He has an array aa of size nn and an integer kk. He can make at most kk operations in the array. In each operation, he picks a single element and increases it by 11.

He found the maximum bitwise AND that array aa can have after at most kk operations.

Theofanis has put a lot of work into finding this value and was very happy with his result. Unfortunately, Adaś, being the evil person that he is, decided to bully him by repeatedly changing the value of kk.

Help Theofanis by calculating the maximum possible bitwise AND for qq different values of kk. Note that queries are independent.

Input Format: The first line contains two integers nn and qq (1n,q1051 \le n, q \le 10^5 and nq105n \cdot q \le 10^5) — the size of the array and the number of queries.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (0ai1060 \le a_i \le 10^6) — the elements of the array.

Next qq lines describe the queries. The ii-th line contains one integer kik_i (0ki10180 \le k_i \le 10^{18}) — the number of operations that can be done in the ii-th query.

Output Format: For each query, print one integer — the maximum bitwise AND that array aa can have after at most kik_i operations.

Note: In the first test case, in the first query, we add 11 in the first and last elements of the array.

Thus, the array becomes [2,3,7,6][2,3,7,6] with bitwise AND equal to 22.

In the second test case, in the first query, we add 11 in the first element, 55 in the second, and 33 in the third and now all the elements are equal to 55.

Sample Cases

Case 1

Input

4 2
1 3 7 5
2
10

Output

2
6

Case 2

Input

3 5
4 0 2
9
8
17
1
3

Output

5
4
7
0
1

Case 3

Input

1 2
10
5
2318381298321

Output

15
2318381298331

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback