Shortest 2 line solution
IntuitionRefer to this video in order to learn to write tabular solutions from memo solutions :- ApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
Refer to this video in order to learn to write tabular solutions from memo solutions :- https://www.youtube.com/watch?v=5p4M8RmeQCU

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    long long maximumTotalCost(vector<int>& nums) {
        int n = nums.size();
        vector<long long> dp(n);
        dp[0] = nums[0];
        for(int i = 1; i < n; i++)
            dp[i] = max(nums[i] + dp[i - 1], (i >= 2 ? dp[i - 2] : 0) + (nums[i - 1] - nums[i]));
        return dp[n - 1];
    }
};
```
['C++']