Under construction

Still being built. Things may change

Nested Candy Boxes

Interview

Time limit3sMemory limit1024 MB

Summary
Given box counts a_i per nesting level, find the fewest boxes to open to collect at least x candies for each query.
Level

Medium5 of 10

Topics
Greedy, Sorting, Prefix sum, Binary search
Solved
No attempts yet

Statement

For New Year, Andrey received a candy box. Inside it he found several identical, smaller boxes, and inside those are even smaller boxes, and so on. Formally, a candy is a box of level 00, and a box of level ii contains aia_i boxes of level i−1i-1. The box Andrey received has level nn.

Today friends will visit Andrey, and he wants to share some candies with them. To do so, he has to open some boxes. Andrey cannot open a box that is inside a box he has not opened yet. For several values of xx, find the minimum number of boxes Andrey must open to get at least xx candies. Andrey does not know yet how many friends will come, so he asks for answers to several values of xx.

Input

The first line contains nn and mm (1≤n,m≤300 0001 \le n, m \le 300\,000), the number of boxes and the number of queries. The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9). The third line contains mm integers x1,x2,…,xmx_1, x_2, \ldots, x_m (1≤xi≤10121 \le x_i \le 10^{12}). It is guaranteed that each xix_i does not exceed the total number of candies in a level nn box.

Output

Print mm integers. The ii-th number is the minimum number of boxes Andrey must open to get at least xix_i candies.

Hint

In the first example, the only candy is hidden under five levels of boxes. In the second example, to get 13 candies Andrey must open the largest box, then two boxes of level 2, and finally five of the six level 1 boxes.

Examples2

  1. Example 1

    Input
    5 1
    1 1 1 1 1
    1
    
    Expected output
    5
    
  2. Example 2

    Input
    3 3
    3 3 3
    2 8 13
    
    Expected output
    3
    5
    8