Ctrl K

The Drill and the Safes

Medium
A safecracker must open every safe on the list: safe i opens once the drill's accumulated charge reaches hardness[i]. The safes may be opened in any order. The drill works like this: - the charge starts at 0 and the charging rate starts at 1; - every minute the charge grows by the current rate; - as soon as the charge reaches (or exceeds) the hardness of the chosen safe, that safe opens, the charge drops back to 0 and the charging rate goes up by boost. Return the smallest number of minutes needed to open all the safes.
Example 1
hardness=[5, 2, 7], boost=2 → 6

Open the hardness-2 safe first: 2 minutes at rate 1. The rate becomes 3, so the hardness-5 safe takes 2 more minutes. At rate 5 the hardness-7 safe takes 2 minutes. Total 6.

Example 2
hardness=[4, 4], boost=1 → 6

The first safe takes 4 minutes at rate 1, the second takes 2 minutes at rate 2.

Constraints
  • 1 ≤ len(hardness) ≤ 8
  • 1 ≤ hardness[i] ≤ 10⁶
  • 1 ≤ boost ≤ 10
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSquare Frame From Sticks MediumSeating by Divisibility MediumCheapest Basket with Bundles MediumGroups With Equal Sums MediumLeast Total Walk to Scooters Medium
loading Python…
Input
hardness=[5, 2, 7], boost=2
Expected
6

Run checks the first 3 tests in your browser. Submit checks all 168 tests on the server, hidden ones included.