CF639D.Bear and Contribution

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn registered users and the ii -th of them has contribution tit_{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 bb minutes to read one blog and upvote it. Author's contribution will be increased by 55 .
  • Limak can spend cc minutes to read one comment and upvote it. Author's contribution will be increased by 11 .

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 kk 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 xx that at least kk registered users have contribution exactly xx .

How much time does Limak need to achieve his goal?

输入格式

The first line contains four integers nn , kk , bb and cc ( 2<=k<=n<=200000,1<=b,c<=10002<=k<=n<=200000,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 nn integers t1,t2,...,tnt_{1},t_{2},...,t_{n} ( ti<=109|t_{i}|<=10^{9} ) where tit_{i} denotes contribution of the ii -th registered user.

输出格式

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

输入输出样例

  • 输入#1

    4 3 100 30
    12 2 6 1
    

    输出#1

    220
    
  • 输入#2

    4 3 30 100
    12 2 6 1
    

    输出#2

    190
    
  • 输入#3

    6 2 987 789
    -8 42 -4 -65 -8 -8
    

    输出#3

    0
    

说明/提示

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

  • He spends 100100 minutes to read one blog of the 44 -th user and increase his contribution from 11 to 66 .
  • Then he spends 430=1204·30=120 minutes to read four comments of the 22 -nd user and increase his contribution from 22 to 66 (four times it was increaded by 11 ).

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

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

  • Spend 230=602·30=60 minutes to read two blogs of the 11 -st user to increase his contribution from 22 to 1212 .
  • Spend 30+10030+100 minutes to read one blog and one comment of the 33 -rd user. His contribution will change from 66 to 6+5+1=126+5+1=12 .
首页