Python 3 || 4 lines, iteration with dp || T/S: 99% / 98%
Here\'s the plan:\n1. We initialize dp1 and dp2 with the first element of nums. These integer variables keep track of the current maximum total that can be obta
Here\'s the plan:\n1. We initialize `dp1` and `dp2` with the first element of `nums`. These integer variables keep track of the current maximum total that can be obtained by either adding(`dp1`) or subtracting(`dp2`) the current element to the previous maximum total.\n\n1. We iterate though `nums`, updating  `dp1` and `dp2` as described in 1) above and selecting the greater of the two as the current maximum total.\n\n1. We return the maximum value as the solution.\n```\nclass Solution:\n    def maximumTotalCost(self, nums: List[int]) -> int:\n\n        dp1 = dp2 = nums.pop(0)                     # <-- 1)\n\n        for n in nums:\n            dp1, dp2 = max(dp1, dp2) + n, dp1 - n   # <-- 2)\n\n        return max(dp1, dp2)                        # <-- 3)\n```\n[https://leetcode.com/problems/maximize-total-cost-of-alternating-subarrays/submissions/1298064470/](https://leetcode.com/problems/maximize-total-cost-of-alternating-subarrays/submissions/1298064470/)\n\nI could be wrong, but I think that time complexity is *O*(*N*) and space complexity is *O*(1), in which *N* ~ `len(nums)`.
['Python', 'Python3']