[Java/C++/Python] Easy and Concise, O(1) Space
Explanation\npos is last element is positive sign.\nneg is last element is negative sign.\n\nAfter the neg, we need to append a positive A[i]\nAfter the pos, we
# **Explanation**\n`pos` is last element is positive sign.\n`neg` is last element is negative sign.\n\nAfter the `neg`, we need to append a positive `A[i]`\nAfter the `pos`, we can append a positive/negative `A[i]`\n<br>\n\n# **Complexity**\nTime `O(n)`\nSpace `O(n)`\n<br>\n\n**Java**\n```java\n    public long maximumTotalCost(int[] A) {\n        long pos = (long)-1e15, neg = 0, tmp;\n        for (int a : A) {\n            tmp = neg;\n            neg = pos - a;\n            pos = Math.max(pos, tmp) + a;\n        }\n        return Math.max(pos, neg);\n    }\n```\n\n**C++**\n```cpp\n    long long maximumTotalCost(vector<int>& A) {\n        long long pos = -1e15, neg = 0, tmp;\n        for (int a : A) {\n            tmp = neg;\n            neg = pos - a;\n            pos = max(pos, tmp) + a;\n        }\n        return max(pos, neg);\n    }\n```\n\n**Python**\n```py\n    def maximumTotalCost(self, A: List[int]) -> int:\n        pos, neg = -inf, 0\n        for a in A:\n            pos, neg = max(pos, neg) + a, pos - a\n        return max(pos, neg)\n```\n
['C', 'Python', 'Java']