C++ || Memoization || Easy Approach
 # Intuition  \n\n\n# Approach\n\nSimply write all the cases that may occur to take an element and to not take it.\nRefer to this youtube video for better under
<!-- # Intuition -->\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSimply write all the cases that may occur to take an element and to not take it.\nRefer to this youtube video for better understanding:\n\n[https://youtu.be/FKuopgfF4-g?si=hlm3185LDUihbex3]()\n\n# Complexity\n- Time complexity: O(N x 2 x 2) \n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N x 2 x 2)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n#define ll long long int\nclass Solution {\npublic:\n    // isStart=0 ---> Fresh start\n    // isStart=1 ---> Continuity\n\n    // sign=0 ---> (+ve) sign for current\n    // sign=1 ---> (-ve) sign for current\n    long long solve(int index,int isStart,int sign,vector<int>& nums,vector<vector<vector<ll>>> &dp){\n        if(index==nums.size()) return 0;\n\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(index+1,1,1,nums,dp));\n        }\n        else{ //Continuity i.e. isStart==1\n            if(sign==1){ //(-ve)sign\n                // Now we have 2 options:\n\n                // 1. Take the current into existing subarray\n                ans = max( ans, -nums[index]+solve(index+1,1,0,nums,dp));\n\n                //2. Create a new subarray starting from the Current index\n                ans = max( ans, solve(index,0,0,nums,dp));\n            }\n            else{ // (+ve)sign i.e. sign==1\n                // Now we have 2 options:\n\n                // 1. Take the current into existing subarray\n                ans = max( ans, nums[index]+solve(index+1,1,1,nums,dp));\n\n                //2. Create a new subarray starting from the Current index\n                ans = max( ans, solve(index,0,0,nums,dp));\n\n            }\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(0,0,0,nums,dp);\n    }\n};\n```
['C++']