C++ || DP
\n# Code\n\nclass Solution {\npublic:\n    long long maximumTotalCost(vector<int>& nums) {\n        long long dp[nums.size()][2];\n        memset(dp, 0, sizeof(
\n# Code\n```\nclass Solution {\npublic:\n    long long maximumTotalCost(vector<int>& nums) {\n        long long dp[nums.size()][2];\n        memset(dp, 0, sizeof(dp));\n        for(int i = 1;i<nums.size();i++){\n            dp[i][0] = max(dp[i-1][0] , dp[i-1][1]) + nums[i];\n            if(nums[i] >= 0){\n                dp[i][1] = max(dp[i-1][0] , dp[i-1][1]) + nums[i];\n            }else{\n                dp[i][1] = dp[i-1][0] - nums[i];\n            }\n        }\n        return max(dp[nums.size()-1][0], dp[nums.size()-1][1]) + nums[0];\n    }\n};\n\nauto init = []()\n{ \n    ios::sync_with_stdio(0);\n    cin.tie(0);\n    cout.tie(0);\n    return \'c\';\n}();\n```
['C++']