Editorialist: Aryan Agarwala
Problem link: ZIO 2019 Problem 2
The only observation to be made in this problem is that when you divide a bacterium into X bacteria, you’re adding (X-1) bacteria to the count.
Thus, this problem can be simplified into:
You have a number K, three numbers A, B, C, and another number N.
Find the minimum number of times you have to add (A-1), (B-1), or (C-1) to K so that you can get N.
The approach to solving this problem is based on greedy and some hit-and-try. You sort A, B, and C in descending order (where A is the largest).
Let N(a) = number of times we added A-1, N(b) = number times of times we added B-1, N(c) = number of times we added C-1
You have to find the answer for each N(a), where N(a) ranges from 04 to (N-K)/(A-1). To do this for each N(a), you first pick the highest N(b) such that K + (A-1)*N(a) + (B-1)*N(b) <= N.. Then, you decide what the maximum value of n(C) can be n(C). If K + (A-1)*N(a) + (B-1)*N(b) + (C-1)*N(c)=N then N(a) + N(b) + N(c) is the answer for that n(A). Else, decrement N(b) and repeat the process with N(c). If you still haven’t found a solution by the time N(b) is 0, there is no solution for that N(a). Decrement N(a) and repeat this process. Do this for all N(a) and choose the smallest answer.
This is a demonstration of the approach on the first part of this problem:
K = 23,
A = 16,
B = 12,
C = 7,
N = 114
|N(a)||N(b)||N(c)||K + (A-1)*N(a) + (B-1)*N(b) + (C-1)*N(c)|
Therefore, the optimal solution for the first subtask is min ( 3+2+4, 2+5+1, 1+2+9, 0+5+6) = 8