100% run time and 100 memory C#
IntuitionUsing dynamic programming with pre and next for sum to i-2 number and i-1 numberApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Using dynamic programming with pre and next for sum to i-2 number and i-1 number
# 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)$$ -->
![image.png](https://assets.leetcode.com/users/images/41f7bc72-71c3-4666-88d6-5a362a72174d_1736335484.6662304.png)

# Code
```csharp []
public class Solution {
    public long MaximumTotalCost(int[] nums) {
        if(nums.Length == 1){
            return nums[0];
        }
        long pre=nums[0];
        long next = nums[1] < 0 ? nums[0]-nums[1] : nums[0]+nums[1];
        long temp;
        for(int i=2;i<nums.Length;i++){
            temp = next;
            if(nums[i] <0 && nums[i-1] <0){
                next = Math.Max(pre+nums[i-1]-nums[i],next+nums[i]);
            }else{
                next= next+(nums[i]>0?nums[i]:-nums[i]);
            }
            pre = temp;
        }
        return next;
    }
}
```
['Dynamic Programming', 'C#']