values and a number max_len. Split the array into contiguous blocks, each at most max_len long. Then, in every block, replace all elements with that block's maximum.
Return the largest possible sum of the array after this replacement.values=[3, 8, 1, 2, 6], max_len=2 → 31
The blocks [3, 8], [1], [2, 6] become [8, 8], [1], [6, 6], for a sum of 29. Nothing does better.
values=[4, 0, 0, 0], max_len=4 → 16
One block over the whole array: four 4s, sum 16.
values=[5, 1, 5], max_len=1 → 11
values=[3, 8, 1, 2, 6], max_len=2
31
Run checks the first 3 tests in your browser. Submit checks all 107 tests on the server, hidden ones included.