DP
\n\n# Code\n\nclass Solution:\n    def maximumTotalCost(self, nums: List[int]) -> int:\n        n = len(nums)\n        @cache\n        def dp(i, ok):\n         
\n\n# Code\n```\nclass Solution:\n    def maximumTotalCost(self, nums: List[int]) -> int:\n        n = len(nums)\n        @cache\n        def dp(i, ok):\n            if i == n: return 0\n            if ok == 1:\n                ans = nums[i] + dp(i+1, 0)\n            else:\n                ans = max(-nums[i] + dp(i+1, 1), dp(i,1))\n            return ans\n        return dp(0, 1)\n```
['Python3']