Assign Wall Boards to Painters to Minimize the Slowest Painter's Time

Implement minPaintTime

A wall's boards — boards[i] units of length each — must be assigned to k painters, each getting a contiguous run of boards (never splitting one, and every painter must get at least one). Every painter paints at the same fixed rate: timePerUnit time units per unit of length. Find the assignment that minimizes the slowest painter's total time, and return that minimized time. Since every painter shares the same rate, comparing painters by their assigned length gives exactly the same ordering as comparing them by time — so the search can work entirely in length units, and only multiply by timePerUnit once, at the very end, instead of repeating the conversion for every candidate. No length limit below the single longest board could ever work, and a limit equal to the wall's total length always needs just one painter — so the answer is guaranteed to fall somewhere between those two bounds. The number of painters needed only ever decreases (or stays flat) as the length limit grows, which makes this a binary search on the answerBinary Search on the AnswerInstead of searching a sorted array, the search runs directly over the space of possible answers (here, every candidate length limit). It works whenever "is this candidate good enough?" is monotonic — once a candidate works, every larger candidate keeps working too. — search directly over candidate length limits rather than trying every possible way to split the boards.

Example 1:

Input: boards = [13,23,38,47], k = 2, timePerUnit = 3

Output: 222

Example 2:

Input: boards = [5,5,5,5], k = 2, timePerUnit = 4

Output: 40

Example 3:

Input: boards = [1,8,11,3], k = 4, timePerUnit = 5

Output: 55

+ 4 hidden test cases run on Submit.

Constraints:

  • 1 ≤ number of boards ≤ 1000
  • 1 ≤ boards[i] ≤ 1000 (units of length)
  • 1 ≤ k ≤ number of boards
  • 1 ≤ timePerUnit ≤ 100

boards =

[13, 23, 38, 47]

k =

2

timePerUnit =

3