Splitting money (Codeforces 1046F)
Tags: Implement, implementation

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 satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.

Input: First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has.Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses.Last line contains two numbers $$$x$$$, $$$f$$$ ($$$1 \leq f < x \leq 10^9$$$) 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: Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.

Note: Alice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.

Sample Inputs:
3
13 7 6
6 2

Sample Outputs:
4

Solution (Python):
n = int(input())
s = list(map(int, input().split()))
(x, f) = map(int, input().split())
ss = 0
for i in s:
    if i > x:
        a = i // (f + x)
        if i % (f + x) > x:
            a += 1
        ss += a
print(ss * f)

Solution (Python):
import sys
input = sys.stdin.readline
for _ in range(1):
    n = int(input())
    a = list(map(int, input().split()))
    (x, f) = map(int, input().split())
    (ba, rem) = (x + f, 0)
    for i in a:
        if i > x:
            y = (i - x) // ba
            rem += y
            i -= y * ba
            if i > x:
                rem += 1
    print(rem * f)

Solution (Python):
def main():
    input()
    return feeToSplitAddresses(tuple(map(int, input().split())))

def feeToSplitAddresses(addresses):
    (nSatoshiesPerAddress, feePerTransaction) = map(int, input().split())
    slittingCost = nSatoshiesPerAddress + feePerTransaction
    nTransactions = sum(((-nSatoshies - feePerTransaction) // slittingCost for nSatoshies in addresses))
    return (-nTransactions - len(addresses)) * feePerTransaction
if __name__ == '__main__':
    print(main())