Rolete
Time limit2sMemory limit1024 MB
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 blinds. The -th blind is lowered by 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 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 seconds. After blinds have already reached the top, the system slows down, and each remaining blind needs seconds to rise by 1 centimeter.
His younger brother Marin came into the room and asked questions. Each question asks for the minimum time needed to raise the blinds so that every blind is lowered by at most 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 , , , and (, ), 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 integers (), the initial state of the blinds.
The third line contains an integer (), the number of questions.
The fourth line contains integers (), the required maximal blind height for each question.
Output
Print numbers on a single line. The -th number is the minimum time needed to raise the blinds so that they are lowered by at most centimeters.