Easy to Understand (intuitive) , Tabulation
Intuition\n Describe your first thoughts on how to solve this problem. \n1. There is no constraints on number of partitions.\n2. we can create as many as we wan
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1. There is no constraints on number of partitions.\n2. we can create as many as we want , think in group of 2 ,at any index     i , think about i , and i - 1 only\n3. Think about these case:\n    a. [-1 , -2] => 1\n    b. [-1 , -2 , -5] => 2\n    c. [-1 , -2 , -5 , -10] => 6\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nIf we have (pos , neg) -> we can always make 2nd element positive.\n\n\n# Complexity\n- Time complexity:\n- O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n- O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n\n# Code\n```\nclass Solution {\npublic:\n    long long maximumTotalCost(vector<int>& nums) {\n        int n = nums.size();\n        \n        long long ans = 0;\n        vector<long long> dp(n, -1e15);\n        dp[0] = nums[0];\n        \n        if(n == 1){\n            return (long long)nums[0];\n        }\n        // I have created base case for first 2 element.\n        if(nums[1] < 0){\n            dp[1] = -1 * nums[1] + nums[0];\n        }else{\n            dp[1] = dp[0] + nums[1];\n        }\n        \n        \n        for(int i = 2 ; i < n ; i++){\n            if(nums[i] < 0){\n                dp[i] = dp[i - 2] + -1 * nums[i] + nums[i-1] ;\n            }\n            dp[i] = max(dp[i] , dp[i - 1] + nums[i]);\n        }\n        \n        return dp[n - 1];\n        \n    }\n};\n```
['Dynamic Programming', 'C++']