Rust/Python 3 lines solution with explanation how to get there
Intuition\n\nFirst it does not name sense to have an division in which we have more than 3 elements. For example if one of the divisions is a1, a2, a3, you can 
# Intuition\n\nFirst it does not name sense to have an division in which we have more than 3 elements. For example if one of the divisions is `a1, a2, a3`, you can do the same with divison `a1, a2` and another one `a3`.\n\nNow we can look at the problem recursively.\n\n```\nf(arr) = max(\n   arr[i] + f(arr[i + 1:]),\n   arr[i] - arr[i + 1] + f(arr[i + 2:]),\n)\n```\n\nJust add boundary conditions and caching to redo the same computations and you have a solution\n\n```\nclass Solution:\n\n  def maximumTotalCost(self, nums: List[int]) -> int:\n    @lru_cache(None)\n    def dp(i):\n      if i >= len(nums):\n        return 0\n\n      if i == len(nums) - 1:\n        return nums[-1]\n\n      return max(\n        nums[i] + dp(i + 1),\n        nums[i] - nums[i + 1] + dp(i + 2)\n      )\n\n    return dp(0)\n```\n\nNow you can see that you can move backwards in the array and do the same computations (you can notice that you need only last 2 results). So you can rewrite it with\n\n# Complexity\n- Time complexity: $O(n)$\n- Space complexity: $O(1)$\n\n# Code\n```Python []\nclass Solution:\n\n  def maximumTotalCost(self, nums: List[int]) -> int:\n    v1, v2 = nums[-1], 0\n    for i in range(len(nums) - 2, -1, -1):\n      v1, v2 = max(nums[i] + v1, nums[i] - nums[i + 1] + v2), v1\n    return v1\n```\n```Rust []\nimpl Solution {\n  pub fn maximum_total_cost(nums: Vec<i32>) -> i64 {\n    let (mut v1, mut v2) = (nums[nums.len() - 1] as i64, 0);\n    for i in (0 .. nums.len() - 1).rev() {\n      (v1, v2) = ((nums[i] as i64 + v1).max(nums[i] as i64 - nums[i + 1] as i64 + v2), v1);\n    }\n    return v1;\n  }\n}\n\n```
['Python3', 'Rust']