C++ O(N) solution .
Intuition\n Describe your first thoughts on how to solve this problem. \nSince in a subarray,  sum is el1 - el2 + el3 - el4 ....\nWe can use subarray of size ei
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSince in a subarray,  sum is el1 - el2 + el3 - el4 ....\nWe can use subarray of size either 1 or 2 .\nRest is DP.\n# Complexity\n- Time complexity:$$O(N)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(N)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n#define ll long long\nclass Solution {\npublic:\n    ll maximumTotalCost(vector<int>& nums) {\n        int n = nums.size();\n        vector<ll> dp(n, 0);\n        dp[n-1] = nums[n-1];\n        for (int i = n - 2; i >= 0; --i) {\n            dp[i] = nums[i];\n            if (i + 1 < n) {\n                dp[i] = max(dp[i], nums[i] - nums[i+1] + (i + 2 < n ? dp[i+2] : 0));\n            }\n            dp[i] = max(dp[i], nums[i] + dp[i+1]);\n        }\n        return dp[0];\n    }\n};\n\n```
['C++']