Easy Iterative dynamic programming
\n\n# Code\n\nclass Solution {\npublic:\n    long long maximumTotalCost(vector<int>& nums) {\n        \n        int n=nums.size();\n    vector<long long>dp1(num
\n\n# Code\n```\nclass Solution {\npublic:\n    long long maximumTotalCost(vector<int>& nums) {\n        \n        int n=nums.size();\n    vector<long long>dp1(nums.size(),0);\n        vector<long long>dp2(nums.size(),0);\n        dp1[0]=nums[0];dp2[0]=nums[0];\n        for(int i=1;i<nums.size();i++){\n            dp1[i]+=nums[i]+max(dp2[i-1],dp1[i-1]);\n            dp2[i]+=(nums[i]*-1)+dp1[i-1];\n        }\n        \n        return max(dp1[n-1],dp2[n-1]);\n    }\n};\n```
['Dynamic Programming', 'C++']