I study algorithms, to learn, I do exercises that appear on sites like leetetcode and hacker rank. There is an exercise that I don't know where to start:

New disease spreads throughout the day

, so that in`i = 0`

a day ago`i-ésimo`

new cases. Fortunately, there is treatment and a hospital can provide treatment. However, the hospital has a`i`

which are available initially on the day`capacidade máxima de camas C`

. The hospital must have a bed available to admit a new patient. The hospital can then treat up to`i = 0`

patients per day and treatment`k`

, which means that the hospital can heal up to`é efetivo após um dia`

patients during the day`k`

and therefore distribute them and make your bed available again the day`i`

. Write an algorithm to find out when the hospital will no longer be able to accept all new patients. It is the first day that one or more patients will not be admitted. Write your solution in a Python function`i + 1`

. The time complexity of your solution should be`Hospital_Overflow(C, k)`

`O(log C)`

.For example, hospital_overflow (5.2) should return 5. Indeed, on day 1, there is 1 patient in the hospital; this patient is cured and released on day 2, when two other patients are admitted; these two are cured on day 3, when three patients are admitted; on day 4, only 2 of the 3 hospital patients are cured and 4 new patients are admitted, filling the 5 beds. Therefore, on the 5th, the hospital will not be able to admit all new cases.

The method I would do would be to create a bunch and add new patients to the queue while deleting those who have been cured, but this has an O (n) complexity. I read that queues with this monotonous property of integers can be resolved in O (log (n)), but I couldn't figure out how, I'm looking for it help to understand how to solve the problem in the required complexity.