Minimum Time to Break Locks I - Problem
Bob is stuck in a dungeon and must break n locks, each requiring some amount of energy to break. The required energy for each lock is stored in an array called strength where strength[i] indicates the energy needed to break the i-th lock.
To break a lock, Bob uses a sword with the following characteristics:
- The initial energy of the sword is 0
- The initial factor
xby which the energy of the sword increases is 1 - Every minute, the energy of the sword increases by the current factor
x - To break the i-th lock, the energy of the sword must reach at least
strength[i] - After breaking a lock, the energy of the sword resets to 0, and the factor
xincreases by a given valuek
Your task is to determine the minimum time in minutes required for Bob to break all n locks and escape the dungeon.
Input & Output
Example 1 — Basic Case
$
Input:
strength = [3,4,1], k = 1
›
Output:
4
💡 Note:
Optimal order: Break lock 2 (1 energy, 1 minute), then lock 1 (4 energy, factor=2, so 2 minutes), then lock 0 (3 energy, factor=3, so 1 minute). Total: 1+2+1=4 minutes.
Example 2 — Higher k Value
$
Input:
strength = [2,5,4], k = 2
›
Output:
5
💡 Note:
Break lock 0 (2 energy, 2 minutes), then lock 2 (4 energy, factor=3, so ceil(4/3)=2 minutes), then lock 1 (5 energy, factor=5, so ceil(5/5)=1 minute). Total: 2+2+1=5 minutes.
Example 3 — Single Lock
$
Input:
strength = [10], k = 3
›
Output:
10
💡 Note:
Only one lock with strength 10, initial factor is 1, so it takes 10 minutes to break.
Constraints
- 1 ≤ n ≤ 8
- 1 ≤ strength[i] ≤ 108
- 1 ≤ k ≤ 108
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code