DP Solution || Just need to think
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    typedef long long ll;\n    long long solve(vector<vector<vector<ll>>>&dp,vector<int>& nums, int index, int isStart, int sign){\n        if(index>=nums.size()) return 0;\n        if(dp[index][isStart][sign] != -1e15) return dp[index][isStart][sign];\n\n        ll ans = -1e15;\n        if(isStart == 0){\n            ans = max(ans,nums[index]+solve(dp,nums,index+1,1,sign^1));\n        }\n        else{\n            if(sign == 1){\n                ans = max(ans,-nums[index]+solve(dp,nums,index+1,1,sign^1));\n                ans = max(ans,solve(dp,nums,index,0,0));\n            }\n            else{\n                ans = max(ans,nums[index]+solve(dp,nums,index+1,1,sign^1));\n                ans = max(ans,solve(dp,nums,index,0,0));\n            }\n        }\n        return dp[index][isStart][sign]= ans;\n    }\n    long long maximumTotalCost(vector<int>& nums) {\n      int n =  nums.size();\n      vector<vector<vector<ll>>>dp(n+1,vector<vector<ll>>(2,vector<ll>(2,-1e15)));\n      return solve(dp,nums,0,0,0);\n    }\n};\n```
['Dynamic Programming', 'C++']