Take not take dp!
Intuition\n Describe your first thoughts on how to solve this problem. \n -> This problem is similar to take not take dp the only twist\nit that we have to take
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n -> This problem is similar to take not take dp the only twist\nit that we have to take all the elements but we can change their sign based on the previous element.\n -> Here we are using f variable to check if we can change the sign of the current element or not (i.e if the previous element was changed than the current element cannot be changed).\n -> We cannot change the first element therefore we have just added it to the answer.\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    private:\n    typedef long long ll;\n    vector<vector<ll>> dp;\n    ll n;\n    ll func(vector<int>&nums,int id,int f){\n        if(id>=n) return 0;\n        if(dp[id][f]!=-1) return dp[id][f];\n         ll take = -1e15,ntake = -1e15;\n        if(f==1){\n            ntake = (-nums[id])+func(nums,id+1,0);\n        }\n        take = nums[id]+func(nums,id+1,1);\n        return dp[id][f] = max(take,ntake);\n    }\npublic:\n    long long maximumTotalCost(vector<int>& nums) {\n        n = nums.size();\n        dp.resize(n+1,vector<ll>(3,-1));\n        return nums[0]+func(nums,1,1);\n        \n    }\n};\n```
['Dynamic Programming', 'C++']