Under construction

Still being built. Things may change

Rolete

Time limit2sMemory limit1024 MB

Summary
For each h, find the minimum time to bring every blind down to at most h cm, mixing manual lifts (t per cm) with the parallel button (s per cm, slowed by k per finished blind).
Level

Medium6 of 10

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

Problem

One Saturday afternoon, Luka woke up from a nap and remembered that COCI was today. Before the contest he had only one thing to do: raise the blinds.

Luka's room has nn blinds. The ii-th blind is lowered by aia_i centimeters from the top of the window. He can raise the blinds in two ways:

  • He can start lifting any single blind manually. This takes tt seconds for each centimeter.
  • He can press a button that starts raising all blinds in parallel at the same speed.

While all blinds are still rising, the button raises each blind by 1 centimeter in ss seconds. After rr blinds have already reached the top, the system slows down, and each remaining blind needs s+k⋅rs + k \cdot r seconds to rise by 1 centimeter.

His younger brother Marin came into the room and asked qq questions. Each question asks for the minimum time needed to raise the blinds so that every blind is lowered by at most hh centimeters. Marin asks every question with respect to the initial state of the blinds.

Luka always raises each blind by a whole number of centimeters.

Input

The first line contains integers nn, tt, ss, and kk (1≤n,t,s≤1051 \le n, t, s \le 10^5, 0≤k≤1050 \le k \le 10^5), the number of blinds, the time to raise a blind manually by 1 centimeter, the time to raise a blind with the button, and the slowing factor of parallel raising.

The second line contains nn integers aia_i (0≤ai≤1050 \le a_i \le 10^5), the initial state of the blinds.

The third line contains an integer qq (1≤q≤1051 \le q \le 10^5), the number of questions.

The fourth line contains qq integers hih_i (0≤hi≤1050 \le h_i \le 10^5), the required maximal blind height for each question.

Output

Print qq numbers on a single line. The ii-th number is the minimum time needed to raise the blinds so that they are lowered by at most hih_i centimeters.

Examples3

  1. Example 1

    Input
    3 2 5 1
    2 2 4
    3
    2 0 1
    
    Expected output
    4 14 9
    
  2. Example 2

    Input
    2 3 4 0
    3 1
    3
    3 2 0
    
    Expected output
    0 3 10
    
  3. Example 3

    Input
    4 3 10 3
    2 4 5 6
    3
    4 3 0
    
    Expected output
    9 18 47