weights. Every bar should weigh at least floor.
One operation takes the two lightest bars x ≤ y, removes them and puts in a single new bar of weight 2·x + y. The operation is only possible while there are at least two bars.
Return the fewest operations after which every bar weighs at least floor.weights=[1, 6, 2, 9], floor=7 → 2
Fuse 1 and 2: 1·2 + 2 = 4, leaving [6, 4, 9]. Then 4 and 6: 4·2 + 6 = 14, leaving [9, 14], all at least 7.
weights=[8, 12, 7], floor=7 → 0
Every bar already weighs at least 7.
weights=[1, 1, 1], floor=5 → 2
1 and 1 give 3, leaving [1, 3]; then 1·2 + 3 = 5.
weights=[1, 6, 2, 9], floor=7
2
Run checks the first 3 tests in your browser. Submit checks all 98 tests on the server, hidden ones included.