10 Lines|O(1) Space|Faster than 100%
Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n\n# Co
# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    long long maximumTotalCost(vector<int>& nums) {\n        long long pp, pm, cp, cm;\n        cp = cm = pp = pm = nums[0];\n        for(int i=1;i<nums.size();i++){\n            cp=max(pp+nums[i], pm+nums[i]);\n            cm=pp-nums[i];\n\n            pp=cp;\n            pm=cm;\n        }\n        return max(cp, cm);\n    }\n};\n```\nSilimar to [CSES - Counting Towers](https://cses.fi/problemset/task/2413)\n\n![Screenshot_2024-11-07_23-48-41.png](https://assets.leetcode.com/users/images/cd6f4365-9536-4f9d-965e-9d2fd376dee0_1731003536.6567175.png)
['Dynamic Programming', 'C++']