values of positive integers. In one move you may pick a run of consecutive elements and replace it with a single number, their sum. For instance, merging [3, 5] in [1, 3, 5, 6] gives [1, 8, 6]. You may make any number of moves, including none.
Return the greatest length a non-decreasing array can have after such moves.values=[6, 1, 2, 4] → 2
After the 6 we need a block summing to at least 6: 1 + 2 + 4 = 7 gives [6, 7]. Three blocks are impossible: the first block is at least 6, and the rest only adds up to one more such block.
values=[2, 2, 5, 9] → 4
The array is already non-decreasing, so nothing needs merging.
values=[4, 3, 2, 7, 1] → 3
For example, [4, 3 + 2, 7 + 1] = [4, 5, 8].
values=[6, 1, 2, 4]
2
Run checks the first 3 tests in your browser. Submit checks all 114 tests on the server, hidden ones included.