problems / 265

Missing Invoice Numbers (easy version)

easy binary-search arrays 1000 ms · 256 MB

Missing Invoice Numbers (easy version)

The billing service numbers its invoices with positive integers. Over the years some numbers were handed out and others were skipped, and finance now wants to reuse the skipped ones. You are given the n invoice numbers that are already used, listed in increasing order. Every other positive integer is free, including all numbers larger than the last used one.

Answer q independent queries. For a query k, print the k-th smallest free invoice number.

Input

The first line contains two integers n and q (1 ≤ n, q ≤ 2·10^5).

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_1 < a_2 < ... < a_n ≤ 10^18), the used invoice numbers in strictly increasing order.

Each of the next q lines contains one integer k (1 ≤ k ≤ 10^18).

Output

For each query, print on its own line the k-th smallest positive integer that does not appear among a_1, ..., a_n.

Notes

In the first example the free numbers are 1, 4, 5, 6, 8, 9, 10, ... (2, 3 and 7 are used).

In the second example every used number lies at the start, so the free numbers are 6, 7, 8, ... The values can exceed the range of a 32-bit integer, and so can the answers: use 64-bit integers.

Example 1

Input

3 5
2 3 7
1
2
3
4
5

Output

1
4
5
6
8

Example 2

Input

5 3
1 2 3 4 5
1
3
1000000000000000000

Output

6
8
1000000000000000005

Hints · reveal one at a time if you're stuck

Hint 1

Starting at k and stepping past the used numbers below it doesn't settle it, because each step can pass more used numbers. Instead, look at the i-th used number a_i (counting from 1): how many free numbers are smaller than it?

Hint 2

That count never decreases as i grows. If you knew how many used numbers are smaller than the answer, how would you get the answer from k? Work out which a_i those are by their free-number count, then find how many there are with a binary search.

report an issue Prefer your own editor? sooks prep 265 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.