C++ || Simple DP Solution
Code\n\nclass Solution {\npublic:\n    // Consider index starts with 1\n    long long dp[100001][2];\n    long long topDown(int i, int oddIndex, vector<int> &nu
# Code\n```\nclass Solution {\npublic:\n    // Consider index starts with 1\n    long long dp[100001][2];\n    long long topDown(int i, int oddIndex, vector<int> &nums){\n        if(i == nums.size()){\n            return 0;\n        }\n        if(dp[i][oddIndex] != -1) {\n            return dp[i][oddIndex];\n        }\n        // Continue in the old subarray\n        long long dontBreak = 0;\n        if(oddIndex){\n            dontBreak = topDown(i+1, !oddIndex, nums) + nums[i];\n        }\n        else{\n            dontBreak = topDown(i+1, !oddIndex, nums) - nums[i];\n        }\n        // Start new subarray\n        long long breakIt = topDown(i+1, true, nums) + nums[i];\n        return dp[i][oddIndex] = max(dontBreak, breakIt);\n    }\n    \n    \n    long long maximumTotalCost(vector<int>& nums) {\n        memset(dp, -1, sizeof(dp));\n        return topDown(0, true, nums);\n    }\n};\n```\n```\ncout << "Upvote the solution if you like it!!" <<endl;\n```
['Dynamic Programming', 'C++']