We have to paint `n`

boards of length `[A1, A2, ..., An]`

. There are `k`

painters available and each takes 1 unit time to paint 1 unit of board. The problem is to find the minimum time to get this job done under the constraints that any painter will only paint continuous sections of boards, say board {2, 3, 4} or only board {1} or nothing but not board {2, 4, 5}.

When `k = 2`

and `A = [10, 10, 10, 10]`

, the output should be `20`

.

When `k = 2`

and `A = [10, 20, 30, 40]`

, the output should be `60`

since we can divide first 3 boards for one painter and the last board for second painter.

Contributed by Berkan Teber

You are not signed in. You can only run/submit code after signing in. Create your free Codela account now!