coded with very hit and trial process || cpp
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```cpp []\nclass Solution {\npublic:\n\n    long long f(int ind , bool prev , vector<int> &nums , int n , vector<vector<long long >> &dp){\n        if(ind  == n) return 0;\n        if(dp[ind][prev] != -1) return dp[ind][prev];\n        long long op1 = LLONG_MIN;\n        long long op2 = LLONG_MIN;\n        long long op3 = LLONG_MIN;\n        long long op4 = LLONG_MIN;\n        if(prev == 1 ){\n            op1 = (-nums[ind] + f(ind+1 , 0 ,nums , n , dp));// adding in prev subArray\n        }\n        else if(prev == 0){\n            op2 = (nums[ind] + f(ind+1, 1 , nums  ,n , dp )); // adding in prev subArray\n        }\n        \n        // creating new subArray from this index\n        op3 = nums[ind] + f(ind+1 , 0 ,  nums , n , dp);\n        return dp[ind][prev] =  max(op1 , max(op2 , max(op3 , op4)));\n    }\n\n    long long maximumTotalCost(vector<int>& nums) {\n        int n = nums.size();\n        bool prev = 0;\n        vector<vector<long long >> dp(n , vector<long long > (2,-1));\n        long long ans1 = f(0 , 0  , nums , n , dp);\n        return ans1;\n    }\n};\n```
['C++']