DP. One line solution. Time O(n). Space O(1)
\nclass Solution:\n    def maximumTotalCost(self, n: List[int]) -> int:\n        return reduce(lambda d, m:(d[1], max(d[0]+m[0]-m[1], d[1]+m[1])), pairwise(n), 
```\nclass Solution:\n    def maximumTotalCost(self, n: List[int]) -> int:\n        return reduce(lambda d, m:(d[1], max(d[0]+m[0]-m[1], d[1]+m[1])), pairwise(n), (0,n[0]))[1]\n```\n> More readable\n```\nclass Solution:\n    def maximumTotalCost(self, nums: List[int]) -> int:\n        dp = (0, nums[0])\n        for a, b in pairwise(nums):\n            dp = (dp[1], max(dp[0]+a-b, dp[1]+b))\n        return dp[1]\n```
['Dynamic Programming', 'Python3']