loads. For a contiguous non-empty segment, take its minimum and its sum and multiply them; call that the segment's score. For example, the segment [4, 2, 7] scores 2 · (4 + 2 + 7) = 26.
Return the largest score over all segments modulo 10⁹ + 7. Maximise the actual value first and only then take the remainder. The maximum before the remainder is guaranteed to fit in a signed 64-bit integer.loads=[4, 1, 6, 5, 3] → 55
The segment [6, 5] has minimum 5 and sum 11, giving 55. [6, 5, 3] gives 3 · 14 = 42 and [6] gives 36; nothing beats 55.
loads=[2, 2, 2] → 12
Take the whole array: 2 · 6 = 12.
loads=[1, 9, 1] → 81
The single element 9 gives 9 · 9 = 81, while the whole array gives only 1 · 11 = 11.
loads=[4, 1, 6, 5, 3]
55
Run checks the first 3 tests in your browser. Submit checks all 104 tests on the server, hidden ones included.