Minimum Time to Finish the Race

You are given a 0-indexed 2D integer array tires where tires[i] = [fi, ri] indicates that the i^th tire can finish its x^th successive lap in fi * ri^(x-1) seconds.

  • For example, if fi = 3 and ri = 2, then the tire would finish its 1^st lap in 3 seconds, its 2^nd lap in 3 * 2 = 6 seconds, its 3^rd lap in 3 * 2^2 = 12 seconds, etc.

You are also given an integer changeTime and an integer numLaps.

The race consists of numLaps laps and you may start the race with any tire. You have an unlimited supply of each tire and after every lap, you may change to any given tire, including the current tire type, if you wait changeTime seconds.

Return the minimum time to finish the race.

Example 1
Inputtires = [[2,3],[3,4]], changeTime = 5, numLaps = 4
Output21
Using tire 0 for two laps, changing to a new tire 0, then using it for two more laps takes 2 + 6 + 5 + 2 + 6 = 21 seconds, which is minimum.
Example 2
Inputtires = [[1,10],[2,2],[3,4]], changeTime = 6, numLaps = 5
Output25
Using tire 1 for two laps, changing to a new tire 1 for two more laps, then changing to tire 0 for the final lap takes 25 seconds, which is minimum.

Constraints

  • 1 <= tires.length <= 10^5
  • tires[i].length == 2
  • 1 <= fi, changeTime <= 10^5
  • 2 <= ri <= 10^5
  • 1 <= numLaps <= 1000

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate