VK Cup 2016 - Round 1
D
Bear and Contribution
Codeforces
2400
原题
← CE →
翻译中…

Codeforces is a wonderful platform and one its feature shows how much someone contributes to the community. Every registered user has contribution — an integer number, not necessarily positive. There are $*n*$ registered users and the $*i*$-th of them has contribution $*t*_{*i*}$.

翻译中…

Limak is a little polar bear and he's new into competitive programming. He doesn't even have an account in Codeforces but he is able to upvote existing blogs and comments. We assume that every registered user has infinitely many blogs and comments.

翻译中…
  • Limak can spend $*b*$ minutes to read one blog and upvote it. Author's contribution will be increased by $5$.
  • Limak can spend $*c*$ minutes to read one comment and upvote it. Author's contribution will be increased by $1$.
翻译中…

Note that it's possible that Limak reads blogs faster than comments.

翻译中…

Limak likes ties. He thinks it would be awesome to see a tie between at least $*k*$ registered users. To make it happen he is going to spend some time on reading and upvoting. After that, there should exist an integer value $*x*$ that at least $*k*$ registered users have contribution exactly $*x*$.

翻译中…

How much time does Limak need to achieve his goal?

翻译中…

Input

翻译中…

The first line contains four integers $*n*$, $*k*$, $*b*$ and $*c*$ ($2 ≤ *k* ≤ *n* ≤ 200 000, 1 ≤ *b*, *c* ≤ 1000$) — the number of registered users, the required minimum number of users with the same contribution, time needed to read and upvote a blog, and time needed to read and upvote a comment, respectively.

翻译中…

The second line contains $*n*$ integers $*t*_{1}, *t*_{2}, ..., *t*_{*n*}$ ($|*t*_{*i*}| ≤ 10^{9}$) where $*t*_{*i*}$ denotes contribution of the $*i*$-th registered user.

翻译中…

Output

翻译中…

Print the minimum number of minutes Limak will spend to get a tie between at least $*k*$ registered users.

翻译中…

Note

翻译中…

In the first sample, there are $4$ registered users and Limak wants a tie between at least $3$ of them. Limak should behave as follows.

翻译中…
  • He spends $100$ minutes to read one blog of the $4$-th user and increase his contribution from $1$ to $6$.
  • Then he spends $4·30 = 120$ minutes to read four comments of the $2$-nd user and increase his contribution from $2$ to $6$ (four times it was increaded by $1$).
翻译中…

In the given scenario, Limak spends $100 + 4·30 = 220$ minutes and after that each of users $2, 3, 4$ has contribution $6$.

翻译中…

In the second sample, Limak needs $30$ minutes to read a blog and $100$ minutes to read a comment. This time he can get $3$ users with contribution equal to $12$ by spending $100 + 3·30 = 190$ minutes:

翻译中…
  • Spend $2·30 = 60$ minutes to read two blogs of the $1$-st user to increase his contribution from $2$ to $12$.
  • Spend $30 + 100$ minutes to read one blog and one comment of the $3$-rd user. His contribution will change from $6$ to $6 + 5 + 1 = 12$.
翻译中…

样例

Input #1
4 3 100 30
12 2 6 1
Output #1
220
InputCopy OutputCopy
Input #2
4 3 30 100
12 2 6 1
Output #2
190
InputCopy OutputCopy
Input #3
6 2 987 789
-8 42 -4 -65 -8 -8
Output #3
0
InputCopy OutputCopy
题目信息
题号
639D
时间限制
4 s
内存限制
256 MB
标签
数据结构
贪心
排序
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。