#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 curtains. For the -th curtain, it is lowered by 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 centimeter takes 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 centimeter in seconds. If curtains are already fully raised, this will slow down the system. Then each remaining curtain needs seconds to rise by 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 questions: What is the minimum time needed so that the maximum lowered height of the curtains does not exceed 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 , 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 integers , describing the initial state of the curtains.
The third line contains an integer , representing the number of questions.
The fourth line contains integers , representing the maximum curtain height.
Output Format
Output one line with integers. The -th integer is the minimum time needed so that the maximum lowered height of the curtains does not exceed 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 centimeters, Luka needs to manually raise the third curtain by centimeters. The fastest way is to raise it manually, which will take him seconds.
If all curtains need to be fully raised, Luka can first manually raise the third curtain by centimeters. Then he can press the button and let all curtains rise by centimeters together. The total time needed is seconds.
Similarly, if the lowered height of the curtains must be at most centimeter, Luka will first manually raise the third curtain by centimeters, and then raise all curtains together by centimeter. The total raising time will be seconds.
Subtasks
| Subtask | Points | Constraints |
|---|---|---|
| 1 | 16 | |
| 2 | 26 | |
| 3 | 32 | |
| 4 | 36 | No additional constraints. |
Translated by ChatGPT 5