loads, in queue order. Crates are shipped until the queue is empty, and every trip works like this:
- if three or more crates remain, pick **any two of the first three** and ship them; the trip costs the larger of the two weights;
- if fewer than three remain, ship them all in one trip; it costs the largest weight among them.
The remaining crates keep their order. Return the smallest total cost of emptying the queue.loads=[4, 9, 3, 5] → 13
First remove 4 and 3 from the front three for max(4, 3) = 4, leaving [9, 5], which go together for 9. Total 13.
loads=[7, 2, 2, 7, 1] → 10
Remove the two 2s for 2, giving [7, 7, 1]; then the two 7s for 7, and the final 1 goes for 1. Total 10.
loads=[6] → 6
A single element is removed in one move for 6.
loads=[4, 9, 3, 5]
13
Run checks the first 3 tests in your browser. Submit checks all 118 tests on the server, hidden ones included.