Beat 100% in both || O(1) space solution || easy to understand
Intuition\n- a means flip nums[i-1]\n- b means not flip nums[i-1]\n- i can flip if only i-1 not flip\n- i can flip or not flip, dependent from the state of i-1,
# Intuition\n- a means flip nums[i-1]\n- b means not flip nums[i-1]\n- i can flip if only i-1 not flip\n- i can flip or not flip, dependent from the state of i-1, so we need to find max value of that two states.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```cpp []\n;class Solution {\npublic:\n    long long maximumTotalCost(vector<int>& nums) {\n        ios::sync_with_stdio(false); cin.tie(0);\n        long long res = 0, a = 0, b = 0;\n        int n = nums.size();\n        for (int i = 0; i < n; i++)\n        {\n            if (i == 0)\n            {\n                res += nums[i];\n                continue;\n            }\n            if (nums[i] >= 0)\n            {\n                res += max(a, b);\n                res += nums[i];\n                a = 0;\n                b = 0;\n            }\n            else\n            {\n                long long tmp1 = a, tmp2 = b;\n                a = tmp2 + (-1)*nums[i];\n                b = max(tmp1 + nums[i], tmp2 + nums[i]);\n            }\n        }\n        return res += max(a, b);\n    }\n};\n```
['C++']