Editorial for Bubble Cup V18 A Splitting Money
Submitting an official solution before solving the problem yourself is a bannable offence.
It’s useful to notice that since we can create multiple addresses for free we never need to transfer bitcoin to an existing address. Therefore, we can solve the problem for each public address separately and sum the fees at the end.
In order to minimize the number of fees we will need to minimize the number of transactions, because the cost per transaction is constant. Therefore, we will need to make transactions as large as possible – in other words . So, if number of satoshies in the address is , we might think we need exactly transactions in order to make them . Unfortunately, this isn’t entirely true because the remainder , can still be larger than . If it is, then we need one extra transaction of size . This solves the problem per one public address.
Another important observation is that even though all numbers on the input are 32-bit integers, given the constraints, sum of the fees per public address can be larger than 32-bit integer allows. So we will need to use 64-bit integer for summation.