Recursion + Memoization
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 {\n    long long maxi = 0;\npublic:\n    long long maximumTotalCost(vector<int>& nums) {\n        long long n = nums.size();\n        vector<vector<long long>> dp(n + 1, vector<long long>(3, -1));\n        return solve(0, nums, 1, dp);\n    }\n    long long solve(int ind, vector<int>& nums, int flag, vector<vector<long long>>& dp) {\n        if (ind >= nums.size()) return 0;\n        if (dp[ind][flag+1] != -1) return dp[ind][flag+1];\n        long long ans = nums[ind] * flag;\n        long long res = solve(ind + 1, nums, flag * -1, dp);\n        long long res1 = solve(ind+1, nums, 1, dp);\n        return dp[ind][flag+1] = max(res, res1) + ans;\n    }\n};\n```
['C++']