#P10260. [COCI 2023/2024 #5] Rolete

[COCI 2023/2024 #5] Rolete

Background

Translated from T4 “Rolete” of COCI 2023/2024 Contest #5

Problem Description

On a Saturday afternoon, Luka woke up from a nap and remembered that COCI is today. Before the contest, he only needs to do one thing: pull up the curtains.

In Luka’s room, there are nn curtains. For the ii-th curtain, it is lowered by aia_i centimeters from the top of the window. He can pull up the curtains in two ways:

  • He can start pulling up any one curtain manually. With this method, pulling up 11 centimeter takes tt seconds.
  • He can press a button, and all curtains will be pulled up together at the same speed, in sync.

When the button is pressed, the lifting speed is defined as follows: if all curtains are moving up, each curtain rises by 11 centimeter in ss seconds. If rr curtains are already fully raised, this will slow down the system. Then each remaining curtain needs s+krs + k \cdot r seconds to rise by 11 centimeter.

COCI is about to start, and Luka wants to raise his curtains as fast as possible. Meanwhile, his brother Marin walks into the room and asks him qq questions: What is the minimum time needed so that the maximum lowered height of the curtains does not exceed hh centimeters? For each question, Marin always considers the initial state of the curtains.

They realized there was not enough time to think about this before COCI. Luckily, this problem also appears here! Help them solve it.

Note: Luka always raises curtains by an integer number of centimeters.

Input Format

The first line contains four integers n,t,s,k (1n,t,s105,0k105)n, t, s, k\ (1\le n,t,s\le 10^5,0\le k\le 10^5), representing the number of curtains, the time needed to manually raise curtains, the time needed when pressing the button, and the slowdown factor for synchronized lifting.

The second line contains nn integers ai (0ai105)a_i\ (0\le a_i\le 10^5), describing the initial state of the curtains.

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

The fourth line contains qq integers hi (0hi105)h_i\ (0\le h_i\le 10^5), representing the maximum curtain height.

Output Format

Output one line with qq integers. The ii-th integer is the minimum time needed so that the maximum lowered height of the curtains does not exceed hih_i centimeters.

3 2 5 1
2 2 4
3
2 0 1

4 14 9

2 3 4 0
3 1
3
3 2 0

0 3 10

4 3 10 3
2 4 5 6
3
4 3 0

9 18 47

Hint

Sample Explanation 1

To make the lowered height of all curtains at most 22 centimeters, Luka needs to manually raise the third curtain by 22 centimeters. The fastest way is to raise it manually, which will take him 44 seconds.

If all curtains need to be fully raised, Luka can first manually raise the third curtain by 22 centimeters. Then he can press the button and let all curtains rise by 22 centimeters together. The total time needed is 4+10=144 + 10 = 14 seconds.

Similarly, if the lowered height of the curtains must be at most 11 centimeter, Luka will first manually raise the third curtain by 22 centimeters, and then raise all curtains together by 11 centimeter. The total raising time will be 99 seconds.

Subtasks

Subtask Points Constraints
1 16 n,q,ai,hi100n,q,a_i,h_i\le 100
2 26 k=0k=0
3 32 q=1q=1
4 36 No additional constraints.

Translated by ChatGPT 5