#P5800. [SEERC 2019] Life Transfer
[SEERC 2019] Life Transfer
Description
In the metropolis Nekoresti, there are people with known ages. The age of the -th person is . They are enjoying their vacation, so they decide to visit Pisiev to tour a famous museum called Koshkseum. They can travel either by car or by motorcycle:
- A car can carry up to people (including one driver whose age is at least , and up to passengers). The rental cost of one car is feli.
- A motorcycle can carry only person (whose age is at least ). The rental cost of one motorcycle is feli.
Unfortunately, these people are not very wealthy, so they ask a local archmage, Mewlin, to help them. By using a powerful spell, Mucadabra, Mewlin can transfer people’s ages. Formally, he can decrease the age of a person with age , while increasing the age of a person with age by the same amount (so the sum of the two ages stays unchanged). The cost to transfer year of age is feli. Due to the limits of the spell, the spell cannot change a person’s age by more than (if a person’s age is , then the changed age can only be within ). Also, an age cannot be less than .
Help them spend the least amount of money to travel from Nekoresti to Pisiev.
Input Format
The first line contains two integers and , representing the number of people traveling and the maximum capacity of one car.
The second line contains four integers and $(1 \leq l_m < l_c \leq 10^5, 1 \leq p_m < p_c \leq 10^5)$, representing the minimum age to drive, the rental cost of one car, the minimum age to ride a motorcycle, and the rental cost of one motorcycle.
The third line contains two integers and , representing the cost to transfer year of age and the limit on how much the spell can change an age.
The fourth line contains integers , where is the age of the -th person.
Output Format
Output one number, the minimum total cost to get everyone to the destination. If there is no solution, output .
2 2
18 1000 16 1
5 3
16 15
1010
2 2
23 10 15 5
2 2
9 20
-1
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号