Bubble Cup V11 A Splitting Money

View as PDF

Submit solution


Points: 7
Time limit: 0.6s
Memory limit: 256M

Problem type

After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.

These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet.

This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most x satoshi (1 bitcoin = 10^8 satoshi). She can create new public address wallets for free and is willing to pay f fee in satoshies per transaction to ensure acceptable speed of transfer. The fee is charged from the address transaction is sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.

Input Specification

First line contains number N representing total number of public addresses Alice has. Next line contains N integer numbers a[i] separated by a single space, representing how many satoshi Alice has in her public addresses.

Last line contains two numbers x and f representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction.

Output Specification

Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.

Constraints

  • 1 \le N \le 200\,000
  • 1 \le a[i] \le 10^9
  • 1 \le f < x \le 10^9

Sample Input

3
13 7 6
6 2

Sample Output

4

Explanation

Alice can make two transactions in a following way:

  1. 13 7 6 (initial state)
  2. 6 7 6 5 (create new address and transfer from first public address 5 satoshi)
  3. 6 4 6 5 1 (create new address transfer from second address 1 satoshi)

Since cost per transaction is 2 satoshi, total fee is 4 satoshi.


Comments

There are no comments at the moment.