A worker can either split into two worker or build a block then dies. Both decisions cost some time.
Given a list blocks, where blocks[i] = k stands for i-th block's building time is k, and cost - the time cost of spliting one worker. Output the shortest time needed to build all blocks.
Initially there is only one worker.
Example 1:
Input: blocks = [1], cost = 1
Output: 1
Explanation: The worker should build the block instead of spliting into two workers, the answer is 1Example 2:
Input: blocks = [1, 2], cost = 5
Output: 7
Explanation: The worker should split into two workers (costs 5 time unit), then build two blocks. The answer is 5 + max(1, 2) = 7.
If the first step is to build a block, the task won't be finished.Example 3:
Input: blocks = [1, 2, 3], cost = 1
Output: 4
Explanation: The worker splits into 2 workers, then one worker builds blocks[2], one splits, lastly we have three workers building blocks simultaneously.
The anwser is 1 + 1 + max(1, 2, 3 - 1) = 4
There is a 3 - 1 because one worker starts building blocks[2] = 3 from the second step, which lasts 1 time unit (i.e. the spliting time cost).