i has tastiness tastiness[i]. You share the bar with friends friends: you make exactly friends cuts between squares and get friends + 1 pieces, each made of consecutive squares.
Your friends get the better pieces and you keep the one with the smallest total tastiness. Cut the bar so that your own piece is as tasty as possible and return its total tastiness.tastiness=[4, 1, 2, 6, 3, 3], friends=2 → 6
Cut into [4, 1, 2], [6] and [3, 3] with totals 7, 6 and 6. You keep a piece worth 6, and no cut does better.
tastiness=[3, 8, 2], friends=2 → 2
Three pieces from three squares allow only one cut layout; the weakest square is worth 2.
tastiness=[5, 5, 5], friends=0 → 15
tastiness=[4, 1, 2, 6, 3, 3], friends=2
6
Run checks the first 3 tests in your browser. Submit checks all 79 tests on the server, hidden ones included.