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