Take not take dp
\n\n# Complexity\n- Time complexity:O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(n)\n Add your space complexity here, e.g. O(n) \n\n
\n\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n#define ll long long\nclass Solution {\npublic:\n    vector<int> nums;\n    int n;\n    ll dp[100001][2];\n    \n    ll solve(int index,bool pos){\n        if(index==n)\n            return 0;\n        \n        if(dp[index][pos]!=-1)\n            return dp[index][pos];\n        \n        if(pos){\n            return dp[index][pos]=max(1ll*nums[index]+solve(index+1,0),1ll*nums[index]+solve(index+1,1));\n        }\n        else{\n            return dp[index][pos]=-1ll*nums[index]+solve(index+1,1);\n        }\n    }\n    \n    long long maximumTotalCost(vector<int>& nums) {\n        this->nums=nums;\n        this->n=nums.size();\n        memset(dp,-1,sizeof(dp));\n        return solve(0,1);\n    }\n};\n```
['Dynamic Programming', 'Greedy', 'C++']