#3376

Minimum Time to Break Locks I

expert · 1110 · lc medium +32 · 32.2% accepted · 104 likes · top 10%

Description

Bob must break n locks in a dungeon; the energy needed to break each lock is stored in array strength, where strength[i] is the energy for the ith lock.

Bob uses a sword with these properties:

- The sword's initial energy is 0.

- The initial energy-increase factor x is 1.

- Each minute the sword gains x more energy.

- To break the ith lock, the sword's energy must reach at least strength[i].

- After breaking a lock the sword resets to 0 energy, and x increases by k.

Return the minimum total time (in minutes) Bob needs to break all n locks.

Code

1
2
3