Haskell Max Double Slice Sum
import Data.Array (Array, array, listArray, (!))
maxDoubleSliceSum :: [Int] -> Int
maxDoubleSliceSum a
| n < 3 = 0
| otherwise = maximum [p1 ! i + p2 ! i | i <- [1 .. n - 2]]
where
n = length a
arr = listArray (0, n - 1) a :: Array Int Int
-- p1 ! i = best sum of a slice ending just before index i, growing left to right
p1list = scanl (\acc i -> max 0 (acc + arr ! (i - 1))) 0 [2 .. n - 2]
p1 = listArray (1, n - 2) p1list :: Array Int Int
-- p2 ! i = best sum of a slice starting just after index i, growing right to left
p2list = scanl (\acc k -> max 0 (acc + arr ! (k + 1))) 0 [n - 3, n - 4 .. 1]
p2 = array (1, n - 2) (zip [n - 2, n - 3 .. 1] p2list) :: Array Int Int
This keeps the best sum ending on the left and starting on the right, then combines them around each middle position.