#P5800. [SEERC 2019] Life Transfer

[SEERC 2019] Life Transfer

Description

In the metropolis Nekoresti, there are nn people with known ages. The age of the ii-th person is aia_i. 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 kk people (including one driver whose age is at least lcl_c, and up to k1k-1 passengers). The rental cost of one car is pcp_c feli.
  • A motorcycle can carry only 11 person (whose age is at least lml_m). The rental cost of one motorcycle is pmp_m 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 xx, while increasing the age of a person with age yy by the same amount (so the sum of the two ages stays unchanged). The cost to transfer 11 year of age is tt feli. Due to the limits of the spell, the spell cannot change a person’s age by more than dd (if a person’s age is xx, then the changed age can only be within [xd,x+d][x-d, x+d]). Also, an age cannot be less than 11.

Help them spend the least amount of money to travel from Nekoresti to Pisiev.

Input Format

The first line contains two integers nn and kk (1n,k105)(1 \leq n, k \leq 10^5), representing the number of people traveling and the maximum capacity of one car.

The second line contains four integers lc,pc,lml_c, p_c, l_m and pmp_m $(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 tt and dd (0t,d105)(0 \leq t, d \leq 10^5), representing the cost to transfer 11 year of age and the limit dd on how much the spell can change an age.

The fourth line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai105)(1 \leq a_i \leq 10^5), where aia_i is the age of the ii-th person.

Output Format

Output one number, the minimum total cost to get everyone to the destination. If there is no solution, output 1-1.

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