weights. The game goes in rounds, and your score starts at 0.
Each round you cut the current row into two non-empty parts, a left one and a right one. The heavier part (the one with the larger total weight) is thrown away, and the total weight of the lighter part is added to your score; the lighter part becomes the row for the next round. If the totals are equal, you choose which part to keep.
The game ends when a single stone is left. Return the highest score you can get.weights=[3, 1, 2, 4] → 5
Cut into [3, 1] and [2, 4]: the lighter part [3, 1] stays, +4. Then cut it into [3] and [1]: [1] stays, +1. That makes 5, and no plan does better.
weights=[5, 5] → 5
The parts are equal, so either may stay: +5, and a single stone is left.
weights=[8] → 0
There is only one stone and nothing to cut, so the score is 0.
weights=[3, 1, 2, 4]
5
Run checks the first 3 tests in your browser. Submit checks all 94 tests on the server, hidden ones included.