There are n regions where some servers are hosted. The number of machines in the i-th region is machineCount[i], where 0 ≤ i < n. It can get difficult to manage all the different regions, so the team decided to move some machines to exactly 3 regions, where the number of machines in the region is given by finalMachineCount[], where 0 ≤ j < 3.
There are two operations that can be performed:
- Add or remove a machine from any existing region. The number of computers in that server should be non-zero before and after the operation. This operation costs 1 unit.
- Move all machines from one region to another existing region at a cost of shiftingCost units. The now-empty region is destroyed in this operation.
Find the minimum cost to shift the machines so that any 3 regions have the counts required in finalMachineCount.
Note: It is possible that there are additional machines left at the end apart from the ones placed in the final 3 regions.
STDIN & FUNCTION
4 machineCount[] size = 4
2
machineCount = [2, 4, 5, 3]
4
5
3
→ finalMachineCount[] size = 3
3
finalMachineCount = [4, 4, 4]
4
4
4
→ shiftingCost = 5
5
Sample Output
2
Explanation
On increasing the number of machines of the 4th region by 1 and decreasing the number of machines of the 3rd region by 1, the new machineCount becomes [2, 4, 4, 4]. The total cost for these operations is 1 + 1 = 2.
Use the 2nd, 3rd, and 4th regions as the required servers, leaving behind the 1st region.
我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。
We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.
