Under construction

Still being built. Things may change

Pastry shop

Time limit2sMemory limit128 MB

Summary
For each oven baking time d, find the minimum total customer waiting time when pies are baked one at a time, starting at time 0.
Level

Hard9 of 10

Topics
Dynamic programming, Divide and conquer, Greedy
Solved
No attempts yet

Problem

You are the owner of a pastry shop that bakes the best pies in town. Every day, nn customers come to your shop, and the ii-th customer arrives at time tit_i. You can start baking a pie at time 0. After arriving, a customer waits until you serve the favourite pie straight out of the oven. Nobody likes cold pies, so a customer may wait for a pie, but a pie must not wait for a customer.

Your oven can bake only one pie at a time and cannot be opened during baking. Every pie takes the same time to bake. You know the arrival time of each customer in advance, so you schedule the baking to minimize the total waiting time of the customers.

Your current oven is worn out, so you are thinking about buying a new one. You have chosen mm oven models. The duration of baking one pie in the ii-th model is did_i. You want the fastest oven, but you are not sure whether you can afford it. For each model, compute the total time the customers would wait if you bought that oven and scheduled the baking optimally.

Input

The first line contains two integers nn and mm (1≤n,m≤2000001 \leq n, m \leq 200000). The second line contains nn integers t1,t2,…,tnt_1, t_2, \ldots, t_n (0≤t1≤t2≤…≤tn≤10120 \leq t_1 \leq t_2 \leq \ldots \leq t_n \leq 10^{12}). Two customers can arrive at the same time. The third line contains mm integers d1,d2,…,dmd_1, d_2, \ldots, d_m (1≤di≤1061 \leq d_i \leq 10^6).

Output

Print exactly mm lines. The ii-th line contains one integer, the minimum total waiting time of the customers when the ii-th oven model is used with optimal baking.

Examples1

  1. Example 1

    Input
    4 3
    3 10 11 23
    4 2 5
    
    Expected output
    4
    1
    6