i-th opponent has strength strength[i]. You start with 0 energy and an energy gain of 1.
Each day your energy grows by the current gain. After that, if your energy is at least the strength of some opponent you have not beaten yet, you may beat them (at most one opponent per day). After a win your energy drops to 0 and your gain goes up by 1.
Opponents can be beaten in any order. Return the fewest days needed to beat them all.strength=[5, 2] → 5
Days 1–2: energy 1 + 1 = 2, beat the opponent of strength 2. The gain becomes 2: days 3–5 give 2 + 2 + 2 = 6 ≥ 5. That is 5 days. Starting with the stronger one takes 5 + 1 = 6 days.
strength=[6, 6, 6] → 11
With gains of 1, 2 and 3 it takes 6, 3 and 2 days: 11 in total.
strength=[1, 10] → 6
Beat the weak one on day 1, then five days of 2 energy each for the strong one: 6.
strength=[5, 2]
5
Run checks the first 3 tests in your browser. Submit checks all 90 tests on the server, hidden ones included.